package io.renren.utils;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import io.renren.dao.xtd.DataContractDaoXtd;
import io.renren.dao.xtd.DataContractXtdDaoXtd;
import io.renren.entity.DataCalculateKEntity;
import io.renren.entity.DataDxRecordEntity;
import io.renren.entity.DataEmpPerformanceEntity;
import io.renren.entity.DataPayrollDxdetailEntity;
import io.renren.entity.DataRecommendRecordEntity;
import io.renren.entity.DictDepartmentEntity;
import io.renren.entity.DictEmployeeEntity;
import io.renren.entity.DirAllAchievement;
import io.renren.entity.EmpAllAchievement;
import io.renren.entity.SysConfigEntity;
import io.renren.entity.xtd.DataAddmoneyEntityXtd;
import io.renren.entity.xtd.DataAreaachiRecordEntityXtd;
import io.renren.entity.xtd.DataAreacheckEntityXtd;
import io.renren.entity.xtd.DataBigareaachiRecordEntityXtd;
import io.renren.entity.xtd.DataBigareacheckEntityXtd;
import io.renren.entity.xtd.DataBranchachiRecordEntityXtd;
import io.renren.entity.xtd.DataBranchcheckEntityXtd;
import io.renren.entity.xtd.DataContractXtdEntityXtd;
import io.renren.entity.xtd.DataDirectcheckEntityXtd;
import io.renren.entity.xtd.DataDirectorachiRecordEntityXtd;
import io.renren.entity.xtd.DataEmpAchi;
import io.renren.entity.xtd.DataEmployeeachiRecordEntityXtd;
import io.renren.entity.xtd.DataFormalcheckEntityXtd;
import io.renren.entity.xtd.DataLostmoneyEntityXtd;
import io.renren.entity.xtd.DataMonthdirectEntityXtd;
import io.renren.entity.xtd.DataPayrollEntityXtd;
import io.renren.entity.xtd.DataRecommendEntityXtd;
import io.renren.entity.xtd.DataRecommendRecordEntityXtd;
import io.renren.entity.xtd.DataTeampayEntityXtd;
import io.renren.entity.xtd.DictDepartmentEntityXtd;
import io.renren.entity.xtd.DictEmployeeEntityXtd;
import io.renren.entity.xtd.DictJobEntityXtd;
import io.renren.entity.xtd.DictWagesTypeEntityXtd;
import io.renren.entity.xtd.EmpMonthShouldAchi;
import io.renren.entity.xtd.EmpOneMonthAchi;
import io.renren.entity.xtd.HisDepartmentEntityXtd;
import io.renren.entity.xtd.HisEmployeeEntityXtd;
import io.renren.entity.xtd.MonthWage;
import io.renren.service.DataCalculateKService;
import io.renren.service.DataDxRecordService;
import io.renren.service.DataEmpPerformanceService;
import io.renren.service.DataPayrollDxdetailService;
import io.renren.service.DictEmployeeService;
import io.renren.service.SysConfigService;
import io.renren.service.xtd.DataAddmoneyServiceXtd;
import io.renren.service.xtd.DataAreaachiRecordServiceXtd;
import io.renren.service.xtd.DataAreacheckServiceXtd;
import io.renren.service.xtd.DataBigareaachiRecordServiceXtd;
import io.renren.service.xtd.DataBigareacheckServiceXtd;
import io.renren.service.xtd.DataBranchachiRecordServiceXtd;
import io.renren.service.xtd.DataBranchcheckServiceXtd;
import io.renren.service.xtd.DataContractServiceXtd;
import io.renren.service.xtd.DataContractXtdServiceXtd;
import io.renren.service.xtd.DataContractpayDetailServiceXtd;
import io.renren.service.xtd.DataDirectcheckServiceXtd;
import io.renren.service.xtd.DataDirectorachiRecordServiceXtd;
import io.renren.service.xtd.DataEmployeeachiRecordServiceXtd;
import io.renren.service.xtd.DataFormalcheckServiceXtd;
import io.renren.service.xtd.DataLostmoneyServiceXtd;
import io.renren.service.xtd.DataMonthdirectServiceXtd;
import io.renren.service.xtd.DataPayrollDxdetailServiceXtd;
import io.renren.service.xtd.DataPayrollServiceXtd;
import io.renren.service.xtd.DataRecommendRecordServiceXtd;
import io.renren.service.xtd.DataRecommendServiceXtd;
import io.renren.service.xtd.DataTeampayServiceXtd;
import io.renren.service.xtd.DictDepartmentServiceXtd;
import io.renren.service.xtd.DictEmployeeServiceXtd;
import io.renren.service.xtd.DictJobServiceXtd;
import io.renren.service.xtd.DictWagesTypeServiceXtd;
import io.renren.service.xtd.HisDepartmentServiceXtd;
import io.renren.service.xtd.HisEmployeeServiceXtd;
import io.renren.service.xtd.impl.DataTeampayServiceImplXtd;
import io.renren.service.xtd.impl.HisDepartmentServiceImplXtd;

public class CalculateUtils {
	/**
	 * 计算总法
	 * @throws ParseException 
	 */
	public static void calculate(String month,BigDecimal days,DataCalculateKService dataCalculateKService,DataContractServiceXtd dataContractServiceXtd,DataDxRecordService dataDxRecordService,DataContractDaoXtd dataContractDaoXtd,DataRecommendServiceXtd dataRecommendServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DataBigareaachiRecordServiceXtd dataBigareaachiRecordServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataBranchachiRecordServiceXtd dataBranchachiRecordServiceXtd,DataRecommendRecordServiceXtd dataRecommendRecordServiceXtd,DictEmployeeService dictEmployeeService,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,SysConfigService sysConfigService,DictWagesTypeServiceXtd dictWagesTypeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DictJobServiceXtd dictJobServiceXtd,DataDirectorachiRecordServiceXtd dataDirectorachiRecordServiceXtd,DataAreaachiRecordServiceXtd dataAreaachiRecordServiceXtd,DataPayrollServiceXtd dataPayrollServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataPayrollDxdetailService dataPayrollDxdetailService,DataAddmoneyServiceXtd dataAddmoneyServiceXtd,DataLostmoneyServiceXtd dataLostmoneyServiceXtd,DataEmpPerformanceService dataEmpPerformanceService,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		Map<String, Object> mapno=new HashMap<>();
		List<DictEmployeeEntityXtd> employeeList = dictEmployeeServiceXtd.queryListXtd(mapno);
		for (DictEmployeeEntityXtd employee : employeeList) {
			//出勤比列算工资
			BigDecimal daysOfAttendance = employee.getDaysOfAttendance();
			BigDecimal divideday = daysOfAttendance.divide(days,4,BigDecimal.ROUND_HALF_UP);
			DataPayrollEntityXtd payroll=new DataPayrollEntityXtd();
			BigDecimal sumAll=new BigDecimal(0);
			String jobno = employee.getJobNo();
			String employeeId = employee.getId();
			String workNo = employee.getWorkno();
			if("11.0".equals(jobno)) {
				jobno="11";
			}
			if("12.0".equals(jobno)) {
				jobno="12";
			}
			if("13.0".equals(jobno)) {
				jobno="13";
			}
			if("14.0".equals(jobno)) {
				jobno="14";
			}
			if("15.0".equals(jobno)) {
				jobno="15";
			}
			if("16.0".equals(jobno)) {
				jobno="16";
			}
			if("17.0".equals(jobno)) {
				jobno="17";
			}
			if("18.0".equals(jobno)) {
				jobno="18";
			}
			//获取所有薪资类型
			/*if("11.0".equals(jobno)) {
				jobno="11";
			}
			if("12.0".equals(jobno)) {
				jobno="12";
			}*/
			DictJobEntityXtd byNo = dictJobServiceXtd.getByNo(jobno);
			/*if(byNo==null) {
				System.out.println("dasdasadadsaa");
			}*/
			DictJobEntityXtd DictJob = dictJobServiceXtd.getAllWagesType(byNo.getId());
			List<DictWagesTypeEntityXtd> wageTypeList = DictJob.getWageTypeList();
			payroll.setPayrollmonth(month);
			String jobId = DictJob.getId();

			payroll.setEmployeeid(employeeId);
			for (DictWagesTypeEntityXtd dictWagesTypeEntityXtd : wageTypeList) {

				String wageName = dictWagesTypeEntityXtd.getWageName();
				String wageCode = dictWagesTypeEntityXtd.getWageCode();
				switch(wageName) {
				case "底薪":
					Map<String, Object> map=new HashMap<>();
					map.put("wageCode", wageCode);
					map.put("jobId", jobId);
					//查找是否为固定值
					DictWagesTypeEntityXtd queryByCodeJobId = dictWagesTypeServiceXtd.queryByCodeJobId(map);
					Integer statementstype = queryByCodeJobId.getStatementstype();
					if(statementstype==0) {
						BigDecimal fixedpay = queryByCodeJobId.getFixedpay();
						payroll.setMonthwage(fixedpay.multiply(divideday));
					}else {						
						MonthWage dxAll = calculateDX(month, employeeId,hisEmployeeServiceXtd,dataDxRecordService, dictEmployeeServiceXtd,sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);					
						BigDecimal dx=dxAll.getThisMonthWage().add(dxAll.getLastMonthWage());
						Map<String, Object> querymap=new HashMap<>();
						querymap.put("employeeId", employeeId);
						querymap.put("calTime", month);
						DataDxRecordEntity querySingle = dataDxRecordService.querySingle(querymap);
						BigDecimal thismonthincome = querySingle.getThismonthincome();
						BigDecimal lastmonthincome = querySingle.getLastmonthincome();
						payroll.setMonthwage(thismonthincome.multiply(divideday).add(lastmonthincome));
					}
					break;
				case "首月底薪":

					BigDecimal firstmonthwage = new BigDecimal( calculateSYDX(month,days,workNo,divideday,dataDxRecordService,dictEmployeeServiceXtd,jobno,employeeId,employee,sysConfigService,hisEmployeeServiceXtd,dataContractpayDetailServiceXtd,dataEmployeeachiRecordServiceXtd,dataPayrollDxdetailService,dataPayrollServiceXtd).get("sum").toString() );
					payroll.setFirstmonthwage(firstmonthwage);
					break;
				case "端口费津贴":
					BigDecimal portfee = calculateDK(month, employeeId,hisEmployeeServiceXtd, dictEmployeeServiceXtd,sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
					payroll.setPortfee(portfee);
					sumAll=sumAll.add(portfee);
					break;
				case "话费补助":
					BigDecimal mobilefee = calculateHF(month, employeeId, dataContractDaoXtd , dictEmployeeService, sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
					payroll.setMobilefee(mobilefee);
					sumAll=sumAll.add(mobilefee);
					break;
				case "业务提成":
					BigDecimal businesspromotion = calculateTC(month, employeeId,hisEmployeeServiceXtd, dictEmployeeServiceXtd, sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
					/*if("00".equals(jobno)||"01".equals(jobno)) {
						businesspromotion=businesspromotion.multiply(new BigDecimal(0.8));
					}*/
					payroll.setBusinesspromotion(businesspromotion);
					sumAll=sumAll.add(businesspromotion);
					break;
				case "单列收入":
					BigDecimal separateMoney = calculateDL(month, employeeId, sysConfigService, dataContractpayDetailServiceXtd);
					payroll.setSeparateMoney(separateMoney);
					sumAll=sumAll.add(separateMoney);
					break;
					/*case "新人卓越奖":
					BigDecimal Newtalent = calculateXRZYJ( month, employeeId, workNo, jobno, employee, dataPayrollServiceXtd, hisEmployeeServiceXtd, dataContractXtdServiceXtd, dataEmployeeachiRecordServiceXtd, sysConfigService);
					payroll.setNewtalent(Newtalent);
					sumAll=sumAll.add(Newtalent);
					break;*/
				case "新人推荐奖励":
					BigDecimal recommendReward = calculateTJ(month, employeeId,dataRecommendServiceXtd,sysConfigService, dataRecommendRecordServiceXtd, dataContractpayDetailServiceXtd, dictEmployeeServiceXtd);
					payroll.setNewrecommend(recommendReward);
					sumAll=sumAll.add(recommendReward);
					break;
				case "主管直接管理津贴":
					//主管所有租赁单总和
					BigDecimal calculateZGTD = calculateTDDL(month, employeeId, "directorNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String zgvalue = sysConfigService.getValue("singleColumn.zg", null);
					//单列提成部分
					BigDecimal zgall = calculateZGTD.multiply(new BigDecimal(zgvalue));
					if("071".equals(jobno)||"072".equals(jobno)||"08".equals(jobno)||"09".equals(jobno)||"010".equals(jobno)) {
						zgall=BigDecimal.ZERO;
					}
					BigDecimal directAllowance = calculateZGZJJT(month,workNo,dataCalculateKService,hisEmployeeServiceXtd,dataContractXtdServiceXtd,dataContractpayDetailServiceXtd,dictDepartmentServiceXtd,dictEmployeeServiceXtd,dataDirectorachiRecordServiceXtd,sysConfigService,hisDepartmentServiceXtd);
					payroll.setDirectordirect(directAllowance.add(zgall));
					sumAll=sumAll.add(directAllowance.add(zgall));
					break;
				case "主管间接管理津贴":
					//主管直接管理津贴里面包含了单列，这里*20%已经能得到所有的，单列不需要另算
					/*BigDecimal calculateZGDLYC = calculateDLYC(month, employeeId, "directorNo","directorBredNo", "Z", dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String yczgvalue = sysConfigService.getValue("singleColumn.yczg", null);
					BigDecimal yczgall = calculateZGDLYC.multiply(new BigDecimal(yczgvalue));*/
					BigDecimal directinAllowance = calculateZGJJJT(month, workNo,dataCalculateKService,hisEmployeeServiceXtd,dataContractXtdServiceXtd, dataContractpayDetailServiceXtd, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataDirectorachiRecordServiceXtd, sysConfigService,hisDepartmentServiceXtd);
					payroll.setDirectorindirect(directinAllowance);
					if("071".equals(jobno)||"072".equals(jobno)||"08".equals(jobno)||"09".equals(jobno)||"010".equals(jobno)) {
						directinAllowance=BigDecimal.ZERO;
					}
					sumAll=sumAll.add(directinAllowance);
					break;
				case "职务津贴":
					Map<String, Object> allowanceMap=new HashMap<>();
					allowanceMap.put("wageCode", wageCode);
					allowanceMap.put("jobId", jobId);

					DictWagesTypeEntityXtd jobAllowance = dictWagesTypeServiceXtd.queryByCodeJobId(allowanceMap);
					BigDecimal allowance = jobAllowance.getFixedpay();
					payroll.setJoballowance(allowance);
					sumAll=sumAll.add(allowance);
					break;
				case "分行直接管理津贴":
					//分行所有租赁单总和
					BigDecimal calculateFHTD = calculateTDDL(month, employeeId, "branchNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String fhvalue = sysConfigService.getValue("singleColumn.fh", null);
					//单列提成部分
					BigDecimal fhall = calculateFHTD.multiply(new BigDecimal(fhvalue));
					BigDecimal calculateFDZJ = calculateFDZJ(month, employeeId,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd,dictEmployeeService, dataBranchachiRecordServiceXtd, sysConfigService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);
					payroll.setBranchdirect(calculateFDZJ.add(fhall));
					sumAll=sumAll.add(calculateFDZJ.add(fhall));
					break;
				case "分行间接管理津贴":
					/*BigDecimal calculateFHDLYC = calculateDLYC(month, employeeId, "branchNo","branchBredNo", "F", dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String ycfhvalue = sysConfigService.getValue("singleColumn.ycfh", null);
					BigDecimal ycfhall = calculateFHDLYC.multiply(new BigDecimal(ycfhvalue));*/
					BigDecimal calculateFHJJ = calculateFHJJ(month, employeeId,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd,dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataBranchachiRecordServiceXtd, sysConfigService, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);
					payroll.setBranchindirect(calculateFHJJ);
					sumAll=sumAll.add(calculateFHJJ);
					break;
				case "区域直接管理津贴":
					BigDecimal calculateQYTD = calculateTDDL(month, employeeId, "areaNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String qyvalue = sysConfigService.getValue("singleColumn.qy", null);
					BigDecimal qyall = calculateQYTD.multiply(new BigDecimal(qyvalue));
					BigDecimal areaAllowance = calculateQYZJJT(month, workNo,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd,dataMonthdirectServiceXtd, dataContractpayDetailServiceXtd, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataAreaachiRecordServiceXtd, sysConfigService,hisDepartmentServiceXtd);
					payroll.setAreadirect(areaAllowance.add(qyall));
					sumAll=sumAll.add(areaAllowance.add(qyall));
					break;
				case "区域间接管理津贴":
					/*BigDecimal calculateQYDLYC = calculateDLYC(month, employeeId, "areaNo","areaBredNo", "Q", dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String ycqyvalue = sysConfigService.getValue("singleColumn.ycqy", null);
					BigDecimal ycqyall = calculateQYDLYC.multiply(new BigDecimal(ycqyvalue));*/
					BigDecimal areainAllowance = calculateQYJJJT(month, workNo,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd, dataMonthdirectServiceXtd,dataContractpayDetailServiceXtd, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataDirectorachiRecordServiceXtd, dataAreaachiRecordServiceXtd, sysConfigService,hisDepartmentServiceXtd);
					payroll.setAreaindirect(areainAllowance);
					sumAll=sumAll.add(areainAllowance);
					break;
				case "大区直接管理津贴":
					BigDecimal calculateDQTD = calculateTDDL(month, employeeId, "bigAreaNo", dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String dqvalue = sysConfigService.getValue("singleColumn.dq", null);
					BigDecimal dqall = calculateDQTD.multiply(new BigDecimal(dqvalue));
					BigDecimal calculateDQZJ = calculateDQZJ(month, employeeId,dataCalculateKService,hisEmployeeServiceXtd, dataContractXtdServiceXtd,dataMonthdirectServiceXtd,dictEmployeeService, dataBigareaachiRecordServiceXtd, sysConfigService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);
					payroll.setBigareadirect(calculateDQZJ.add(dqall));
					sumAll=sumAll.add(calculateDQZJ.add(dqall));
					break;
				case "大区间接管理津贴":
					/*BigDecimal calculateDQDLYC = calculateDLYC(month, employeeId, "bigAreaNo","bigAreaBredNo", "D", dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String ycdqvalue = sysConfigService.getValue("singleColumn.ycdq", null);
					BigDecimal ycdqall = calculateDQDLYC.multiply(new BigDecimal(ycdqvalue));*/
					BigDecimal calculateDQJJ = calculateDQJJ(month, employeeId,dataCalculateKService,hisEmployeeServiceXtd,dataContractXtdServiceXtd, dataMonthdirectServiceXtd,dictEmployeeService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataBigareaachiRecordServiceXtd, sysConfigService, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);
					payroll.setBranchindirect(calculateDQJJ);
					sumAll=sumAll.add(calculateDQJJ);
					break;
				case "社会保险":
					Integer hasSocial = employee.getHasSocial();
					Map<String, Object> mapsocial=new HashMap<>();
					mapsocial.put("wageCode", wageCode);
					mapsocial.put("jobId", jobId);
					DictWagesTypeEntityXtd social = dictWagesTypeServiceXtd.queryByCodeJobId(mapsocial);
					BigDecimal fixedpay = social.getFixedpay();
					if(hasSocial!=null) {
						if(hasSocial==0) {
							fixedpay = new BigDecimal(0);
						}
					}
					payroll.setSocialinsurance(fixedpay);
					sumAll=sumAll.subtract(fixedpay);
					break;
				case "住房公积金":
					Integer hasHousing = employee.getHasHousing();
					Map<String, Object> housing=new HashMap<>();
					housing.put("wageCode", wageCode);
					housing.put("jobId", jobId);
					DictWagesTypeEntityXtd house = dictWagesTypeServiceXtd.queryByCodeJobId(housing);
					BigDecimal housingFee = house.getFixedpay();
					if(hasHousing!=null) {
						if(hasHousing==0) {
							housingFee = new BigDecimal(0);
						}
					}
					payroll.setHousingfund(housingFee);
					sumAll=sumAll.subtract(housingFee);
					break;
				}
			}
			if(payroll!=null) {
				if(payroll.getFirstmonthwage()!=null) {
					if(payroll.getFirstmonthwage().compareTo(new BigDecimal(0))==1) {
						payroll.setMonthwage(new BigDecimal(0));
						sumAll=sumAll.add(payroll.getFirstmonthwage());
					}else {
						sumAll=sumAll.add(payroll.getMonthwage());
					}	
				}else {
					sumAll=sumAll.add(payroll.getMonthwage());
				}
			}
			String[] split = month.split("-");
			//年
			String year=split[0];
			//月
			String mm=split[1];
			//奖励
			Map<String, Object> map=new HashMap<>();
			map.put("workNo", workNo);
			map.put("year", year);
			map.put("month", mm);
			//此人所有增项
			BigDecimal addAll =new BigDecimal(0);
			List<DataAddmoneyEntityXtd> addByPar = dataAddmoneyServiceXtd.getAddByPar(map);
			if(addByPar!=null) {
				for (DataAddmoneyEntityXtd dataAddmoneyEntityXtd : addByPar) {
					BigDecimal money = dataAddmoneyEntityXtd.getMoney();
					addAll=addAll.add(money);
				}
			}
			payroll.setReward(addAll);
			sumAll=sumAll.add(addAll);
			//扣款项
			BigDecimal lostAll =new BigDecimal(0);
			List<DataLostmoneyEntityXtd> lostByPar = dataLostmoneyServiceXtd.getLostByPar(map);
			if(lostByPar!=null) {
				for (DataLostmoneyEntityXtd dataLostmoneyEntityXtd : lostByPar) {
					BigDecimal money = dataLostmoneyEntityXtd.getMoney();
					lostAll=lostAll.add(money);
				}
			}

			payroll.setPunishment(lostAll);
			sumAll=sumAll.subtract(lostAll);

			payroll.setJobno(jobno);
			//绩效排名和绩效工资
			DataEmpPerformanceEntity empPer = dataEmpPerformanceService.queryObject(workNo);
			String order = empPer.getOrder();
			BigDecimal money = empPer.getMoney();
			sumAll=sumAll.add(money);
			payroll.setTotalMoney(sumAll);
			payroll.setPerformanceMoney(money);
			payroll.setOrder(order);
			dataPayrollServiceXtd.save(payroll);
			//计算过程量的保存
			insertRecord(month, employeeId,hisEmployeeServiceXtd,dictEmployeeServiceXtd,sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
		}
	}




	/**
	 * 传入区间内数和property配置的key，得到对应区间的value
	 * @param sysConfigService
	 * @param totalAChi
	 * @param key
	 * @return
	 */
	public static BigDecimal getCoefficient(SysConfigService sysConfigService,BigDecimal totalAChi,String key) {
		String tcqj = PropertyUtils.getValue(key);
		BigDecimal coefficient=null;
		Map<String, Object> map=new HashMap<>();
		map.put("key", tcqj);
		List<SysConfigEntity> queryList = sysConfigService.queryList(map);
		for (SysConfigEntity sysConfigEntity : queryList) {
			String value = sysConfigEntity.getValue();
			String[] split = value.split("-");
			if(split.length==3) {
				BigDecimal min=new BigDecimal(split[0]);
				BigDecimal max=new BigDecimal(split[1]);

				if(!(totalAChi.compareTo(min)==-1)&&totalAChi.compareTo(max)==-1) {
					coefficient=new BigDecimal(split[2]);
				}
			}			
		}			
		return coefficient;	
	}



	/**
	 * 传入区间内数和property配置的key，得到对应区间的value
	 * @param sysConfigService
	 * @param totalAChi
	 * @param key
	 * @return
	 */
	public static BigDecimal choseCoefficient(SysConfigService sysConfigService,BigDecimal totalAChi,String key,Integer location) {
		String tcqj = PropertyUtils.getValue(key);
		BigDecimal coefficient=null;
		Map<String, Object> map=new HashMap<>();
		map.put("key", tcqj);
		List<SysConfigEntity> queryList = sysConfigService.queryList(map);
		for (SysConfigEntity sysConfigEntity : queryList) {
			String value = sysConfigEntity.getValue();
			String[] split = value.split("-");
			if(split.length==5) {
				BigDecimal min=new BigDecimal(split[0]);
				BigDecimal max=new BigDecimal(split[1]);

				if(!(totalAChi.compareTo(min)==-1)&&totalAChi.compareTo(max)==-1) {
					coefficient=new BigDecimal(split[location+1]);
				}
			}			
		}			
		return coefficient;	
	}

	/**
	 * 计算底薪的方法(除固定底薪外通用)
	 */
	public static MonthWage calculateDX(String month,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataDxRecordService dataDxRecordService,DictEmployeeServiceXtd dictEmployeeServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd) {
		BigDecimal sum=new BigDecimal(0);
		if("c375e0ebeeaa41cfa9fea3a1b87abb3e".equals(employeeId)) {
			System.out.println();
		}
		//主管和顾问底薪统减200
		BigDecimal diff=new BigDecimal(200);
		BigDecimal thisSum=new BigDecimal(0);
		BigDecimal lastSum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String workno = employee.getWorkno();
		String jobNo = employee.getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		BigDecimal coff=new BigDecimal("1");

		if("00".equals(jobNo)||"01".equals(jobNo)) {
			coff=new BigDecimal("0.8");
		}
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("employeeId",employeeId);
		boolean flag=false;
		List<EmpAllAchievement> contractListByEmpId = dataContractpayDetailServiceXtd.getContractListByEmpId( map);
		//这里如果本月没有开单，实收为0则也应该有底薪，为1500
		if(contractListByEmpId.size()!=0) {
			for (EmpAllAchievement empAllAchievement : contractListByEmpId) {
				//如果是本月就则为真，则不需要再去计算本月底薪
				if(month.replace("-","").equals(empAllAchievement.getContractMonth())) {
					flag=true;
				}
				//合同年月
				String contractMonth = empAllAchievement.getContractMonth();
				BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
				Map<String, Object> sqlmap=new HashMap<>();
				sqlmap.put("month", contractMonth);
				sqlmap.put("employeeId",employeeId);
				List<DataEmployeeachiRecordEntityXtd> queryObjectByMonth = dataEmployeeachiRecordServiceXtd.queryObjectByMonth(sqlmap);
				if(queryObjectByMonth.size()==0) {
					BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi,"dxqj");
					if(Integer.parseInt(jobNo)<7||"072".equals(jobNo)) {
						//如果是7主管和经纪人职级，或者是072职级都要减去diff的值
						coefficient=coefficient.subtract(diff);
					}else if(Integer.parseInt(jobNo)<11&&Integer.parseInt(jobNo)>7) {
						System.out.println(jobNo);
						if(new BigDecimal(2500).compareTo(coefficient)==1) {
							coefficient=new BigDecimal(2500);
						}
					}
					sum=sum.add(coefficient.multiply(coff));
					thisSum=thisSum.add(coefficient.multiply(coff));
				}else {
					//选取第一个记录
					DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryObjectByMonth.get(0);
					//获得总业绩
					BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
					String calTime = dataEmployeeachiRecordEntityXtd.getCalTime();
					//获取累计薪资
					BigDecimal totalincome = dataEmployeeachiRecordEntityXtd.getTotalincome();
					BigDecimal add = oneMonthAchi.add(totalachievement);
					BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, add,"dxqj");
					if(Integer.parseInt(jobNo)<7||"072".equals(jobNo)) {
						//如果是7主管和经纪人职级，或者是072职级都要减去diff的值
						coefficient=coefficient.subtract(diff);
					}else if(Integer.parseInt(jobNo)<11&&Integer.parseInt(jobNo)>7) {
						System.out.println(jobNo);
						if(new BigDecimal(2500).compareTo(coefficient)==1) {
							coefficient=new BigDecimal(2500);
						}
					}
					if("00".equals(jobNo)||"01".equals(jobNo)) {
						coefficient=coefficient.multiply(coff).subtract(totalincome/*.subtract(diff)*/);//回溯的时候没有-200导致为负数

					}else {
						//根据回溯月得到当时的职级
						Map<String, Object> hisMap=new HashMap<>();
						hisMap.put("workNo", workno);
						hisMap.put("hisyear", calTime.substring(0, 4));
						hisMap.put("hismonth", calTime.substring(5, 7));
						HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(hisMap);
						String jobno2 = queryEmployeeByInOrgTime.getJobno();
						BigDecimal coff2=new BigDecimal("1");
						//只有一种情况历史非正式不需要打折，那就是本月为正式，若本月还是非正式那继续打折
						if(("00".equals(jobno2)||"01".equals(jobno2))&&(!("00".equals(jobNo)||"01".equals(jobNo)))) {
							coff2=new BigDecimal("0.8");
						}
						totalincome=totalincome.divide(coff2,2, BigDecimal.ROUND_HALF_UP);
						coefficient=coefficient.multiply(coff).subtract(totalincome);

					}

					sum=sum.add(coefficient);
					lastSum=lastSum.add(coefficient);
				}
			}
		}else {
			BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, new BigDecimal(0),"dxqj");
			if(Integer.parseInt(jobNo)<7||"072".equals(jobNo)) {
				//如果是7主管和经纪人职级，或者是072职级都要减去diff的值
				coefficient=coefficient.subtract(diff);
			}else if(Integer.parseInt(jobNo)<11&&Integer.parseInt(jobNo)>7) {
				System.out.println(jobNo);
				if(new BigDecimal(2500).compareTo(coefficient)==1) {
					coefficient=new BigDecimal(2500);
				}
			}
			sum=sum.add(coefficient.multiply(coff));
			thisSum=thisSum.add(coefficient.multiply(coff));
		}
		if(!flag&&contractListByEmpId.size()!=0) {
			BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, new BigDecimal(0),"dxqj");
			System.out.println(coefficient);
			if(Integer.parseInt(jobNo)<7||"072".equals(jobNo)) {
				//如果是7主管和经纪人职级，或者是072职级都要减去diff的值
				coefficient=coefficient.subtract(diff);
				System.out.println(coefficient);
			}else if(Integer.parseInt(jobNo)<11&&Integer.parseInt(jobNo)>7) {
				System.out.println(jobNo);
				if(new BigDecimal(2500).compareTo(coefficient)==1) {
					coefficient=new BigDecimal(2500);
				}
			}
			sum=sum.add(coefficient.multiply(coff));
			thisSum=thisSum.add(coefficient.multiply(coff));
		}
		Map<String, Object> querymap=new HashMap<>();
		querymap.put("employeeId", employeeId);
		querymap.put("calTime", month);
		DataDxRecordEntity querySingle = dataDxRecordService.querySingle(querymap);
		if(querySingle==null) {
			DataDxRecordEntity dxall=new DataDxRecordEntity();
			dxall.setCaltime(month);
			dxall.setEmployeeid(employeeId);
			dxall.setLastmonthincome(lastSum);
			dxall.setThismonthincome(thisSum);
			dataDxRecordService.save(dxall);
		}
		MonthWage monthWage=new MonthWage();
		monthWage.setThisMonthWage(thisSum);
		monthWage.setLastMonthWage(lastSum);

		return monthWage;
	}
	/**
	 * 提成算法(通用)
	 */
	public static BigDecimal calculateTC(String month,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd) {
		BigDecimal sum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String jobNo = employee.getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		String workno = employee.getWorkno();	
		BigDecimal coff=new BigDecimal("1");
		if("00".equals(jobNo)||"01".equals(jobNo)) {
			coff=new BigDecimal("0.8");
		}
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("employeeId", employeeId);
		List<EmpAllAchievement> contractListByEmpId = dataContractpayDetailServiceXtd.getContractListByEmpId( map);
		for (EmpAllAchievement empAllAchievement : contractListByEmpId) {
			String contractMonth = empAllAchievement.getContractMonth();
			BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
			Map<String, Object> sqlmap=new HashMap<>();
			sqlmap.put("month", contractMonth);
			sqlmap.put("employeeId",employeeId);
			List<DataEmployeeachiRecordEntityXtd> queryObjectByMonth = dataEmployeeachiRecordServiceXtd.queryObjectByMonth(sqlmap);
			if(queryObjectByMonth.size()==0) {
				BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi, "tcqj");
				BigDecimal multiply = coefficient.multiply(oneMonthAchi);
				sum=sum.add(multiply.multiply(coff));
			}else {
				//选取第一个记录
				DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryObjectByMonth.get(0);
				//获得总业绩
				BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
				//获取计算年月
				String calTime = dataEmployeeachiRecordEntityXtd.getCalTime();
				//获取累计提成
				BigDecimal totalextract = dataEmployeeachiRecordEntityXtd.getTotalextract();
				BigDecimal add = oneMonthAchi.add(totalachievement);
				BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, add,"tcqj");
				BigDecimal multiply=coefficient.multiply(add);
				//如果是02职级及以上，那本月回溯的被减数不打折，否则新人卓越奖会算多
				if("00".equals(jobNo)||"01".equals(jobNo)) {
					multiply=multiply.multiply(coff).subtract(totalextract);

				}else {
					//根据回溯月得到当时的职级
					Map<String, Object> hisMap=new HashMap<>();
					hisMap.put("workNo", workno);
					hisMap.put("hisyear", calTime.substring(0, 4));
					hisMap.put("hismonth", calTime.substring(5, 7));
					HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(hisMap);
					String jobno2 = queryEmployeeByInOrgTime.getJobno();
					BigDecimal coff2=new BigDecimal("1");
					//只有一种情况历史非正式不需要打折，那就是本月为正式，若本月还是非正式那继续打折
					if(("00".equals(jobno2)||"01".equals(jobno2))&&(!("00".equals(jobNo)||"01".equals(jobNo)))) {
						coff2=new BigDecimal("0.8");
					}
					totalextract=totalextract.divide(coff2,2, BigDecimal.ROUND_HALF_UP);
					multiply=multiply.multiply(coff).subtract(totalextract);

				}
				sum=sum.add(multiply);
			}
		}
		return sum;
	}
	/**
	 * 单列算法
	 */
	public static BigDecimal calculateDL(String month,String employeeId,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd) {
		BigDecimal sum=new BigDecimal(0);
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("employeeId", employeeId);
		List<EmpAllAchievement> zlContractList = dataContractpayDetailServiceXtd.getZLContractListByEmpId(map);	
		for (EmpAllAchievement empAllAchievement : zlContractList) {
			BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
			String value = sysConfigService.getValue("singleColumn.br", null);
			sum=oneMonthAchi.multiply(new BigDecimal(value)).add(sum);
		}


		return sum;

	}
	/**
	 * 端口津贴
	 */
	public static BigDecimal calculateDK(String month,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd) {
		BigDecimal sum=new BigDecimal(0);
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("employeeId", employeeId);
		DictEmployeeEntityXtd empByUserid = dictEmployeeServiceXtd.queryObjectXtd(employeeId);
		if("d3904feab81e405a959aa15a6b4fbac5".equals(employeeId)) {
			System.out.println(1111);
		}
		List<EmpAllAchievement> contractListByEmpId = dataContractpayDetailServiceXtd.getContractListByEmpId( map);
		//本月总业绩
		BigDecimal thisMonthAch=BigDecimal.ZERO;
		//本月端口费
		BigDecimal thisPort=BigDecimal.ZERO;
		for (EmpAllAchievement empAllAchievement : contractListByEmpId) {
			String contractMonth = empAllAchievement.getContractMonth();
			BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
			Map<String, Object> sqlmap=new HashMap<>();
			sqlmap.put("month", contractMonth);
			sqlmap.put("employeeId",employeeId);
			List<DataEmployeeachiRecordEntityXtd> queryObjectByMonth = dataEmployeeachiRecordServiceXtd.queryObjectByMonth(sqlmap);
			//如果是找不到任何记录，则就是本月的记录
			if(queryObjectByMonth.size()==0) {
				BigDecimal portFee =new BigDecimal(0);
				//是否开端口的判断
				DictEmployeeEntityXtd queryObjectXtd = dictEmployeeServiceXtd.queryObjectXtd(employeeId);
				Integer hasPorts = queryObjectXtd.getHasPorts();
				if(hasPorts==1){
					portFee = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi, "dkqj");	
				}else if(hasPorts==2){
					portFee = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi, "2dkqj");	
				}
				thisMonthAch=oneMonthAchi;
				thisPort=portFee;
				sum=sum.add(portFee);
			}else {
				//判断历史表里面是否开端口
				Map<String,Object> hismap=new HashMap<>();
				hismap.put("workNo", empByUserid.getWorkno());
				hismap.put("hisyear", contractMonth.substring(0, 4));
				hismap.put("hismonth", contractMonth.substring(4, 6));
				HisEmployeeEntityXtd hisEmp = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(hismap);
				Integer hasports = hisEmp.getHasports();
				if(hasports==1) {
					//开端口则进行计算
					DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryObjectByMonth.get(0);
					//获得总业绩
					BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
					//获取累计薪资
					BigDecimal totalportfee = dataEmployeeachiRecordEntityXtd.getTotalportfee();
					BigDecimal add = oneMonthAchi.add(totalachievement);
					BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, add,"dkqj");
					coefficient=coefficient.subtract(totalportfee);
					sum=sum.add(coefficient);
				}else if(hasports==2) {
					//开端口则进行计算
					DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryObjectByMonth.get(0);
					//获得总业绩
					BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
					//获取累计薪资
					BigDecimal totalportfee = dataEmployeeachiRecordEntityXtd.getTotalportfee();
					BigDecimal add = oneMonthAchi.add(totalachievement);
					BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, add,"2dkqj");
					coefficient=coefficient.subtract(totalportfee);
					sum=sum.add(coefficient);
				}

			}
			//如果是季度末期3，6，9，12月则要把平均业绩对应的区间作为每月的应发端补，再扣除之前所发放的
			String checkMonth = month.substring(5, 7);
			String checkyear = month.substring(0, 4);
			Integer lastHasports =null;
			Integer lastLastHasports =null;
			if("03".equals(checkMonth)||"06".equals(checkMonth)||"09".equals(checkMonth)||"12".equals(checkMonth)) {
				//如果是一个季度开的不同端口，则不补偿
				//首先确定是开的同一种类的端口
				Integer thisMonth = Integer.parseInt(checkMonth);
				//获得本月开端口情况
				Integer hasPorts = empByUserid.getHasPorts();
				Integer lastMonth=thisMonth-1;
				Integer lastLastMonth=lastMonth-1;
				//首先判断上个月的人力开端口情况
				Map<String,Object> lastmap=new HashMap<>();
				lastmap.put("workNo", empByUserid.getWorkno());
				lastmap.put("hisyear", checkyear);
				lastmap.put("hismonth", lastMonth);
				HisEmployeeEntityXtd lastEmp = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(lastmap);
				//上上个月
				lastmap.put("hismonth", lastLastMonth);
				HisEmployeeEntityXtd lastLastEmp = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(lastmap);
				if(lastEmp!=null) {
					lastHasports = lastEmp.getHasports();
				}
				if(lastLastEmp!=null) {
					lastLastHasports = lastLastEmp.getHasports();
				}
				//平均业绩
				BigDecimal avgAchi=BigDecimal.ZERO;
				//首月为空，第二个月不为空的情况
				if(lastLastHasports==null&&lastHasports!=null) {
					if(hasPorts==lastHasports) {
						//两个月端口号一致
						BigDecimal portFee=BigDecimal.ZERO;
						BigDecimal totalportfee=BigDecimal.ZERO;
						BigDecimal totalachievement=BigDecimal.ZERO;
						//查看两个月的业绩
						//上个月
						Map<String, Object> lastMap=new HashMap<>();
						lastMap.put("recordTime", checkyear+""+(lastMonth<10?"0"+lastMonth:lastMonth));
						lastMap.put("employeeId",employeeId);
						List<DataEmployeeachiRecordEntityXtd> queryNewestRecord = dataEmployeeachiRecordServiceXtd.queryNewestRecord(lastMap);
						if(queryNewestRecord.size()!=0) {
							DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryNewestRecord.get(0);
							//上个月总业绩
							totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
							//上个月总端口费
							totalportfee = dataEmployeeachiRecordEntityXtd.getTotalportfee();					
						}
						BigDecimal add = totalachievement.add(thisMonthAch);
						//两个月平均业绩
						avgAchi=add.divide(new BigDecimal(2), 2);
						if(hasPorts==1) {
							portFee = CalculateUtils.getCoefficient(sysConfigService, avgAchi,"dkqj");
							System.out.println(portFee);

						}else if(hasPorts==2) {
							portFee = CalculateUtils.getCoefficient(sysConfigService, avgAchi,"2dkqj");
							System.out.println(portFee);
						}
						BigDecimal addport=portFee.multiply(new BigDecimal(2)).subtract(thisPort).subtract(totalportfee);
						System.out.println(addport);					
						if(BigDecimal.ZERO.compareTo(addport)==1) {
							addport=BigDecimal.ZERO;
						}
						sum=sum.add(addport);
					}

				}
				//三个月都不为空
				if(lastLastHasports!=null&&lastHasports!=null) {
					if(hasPorts==lastHasports&&lastHasports==lastLastHasports) {
						//两个月端口号一致
						BigDecimal portFee=BigDecimal.ZERO;
						BigDecimal lastTotalportfee=BigDecimal.ZERO;
						BigDecimal lastLastTotalportfee=BigDecimal.ZERO;
						BigDecimal totalachievement=BigDecimal.ZERO;
						BigDecimal totalachievement2=BigDecimal.ZERO;
						//查看两个月的业绩
						//上个月
						Map<String, Object> lastMap=new HashMap<>();
						lastMap.put("recordTime", checkyear+""+(lastMonth<10?"0"+lastMonth:lastMonth));
						lastMap.put("employeeId",employeeId);
						List<DataEmployeeachiRecordEntityXtd> queryNewestRecord = dataEmployeeachiRecordServiceXtd.queryNewestRecord(lastMap);
						lastMap.put("recordTime", checkyear+""+(lastLastMonth<10?"0"+lastLastMonth:lastLastMonth));
						List<DataEmployeeachiRecordEntityXtd> queryNewestRecord2 = dataEmployeeachiRecordServiceXtd.queryNewestRecord(lastMap);
						if(queryNewestRecord.size()!=0) {
							DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryNewestRecord.get(0);
							//上个月总业绩
							totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();
							//上个月总端口费
							lastTotalportfee = dataEmployeeachiRecordEntityXtd.getTotalportfee();
																																	
						}
						if(queryNewestRecord2.size()!=0) {
							DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd2 = queryNewestRecord2.get(0);
							//上个月总业绩
							totalachievement2 = dataEmployeeachiRecordEntityXtd2.getTotalachievement();
							//上个月总端口费
							lastLastTotalportfee = dataEmployeeachiRecordEntityXtd2.getTotalportfee();
							
						}
						BigDecimal add = totalachievement2.add(totalachievement).add(thisMonthAch);
						//两个月平均业绩
						avgAchi=add.divide(new BigDecimal(3), 2);
						if(hasPorts==1) {
							portFee = CalculateUtils.getCoefficient(sysConfigService, avgAchi,"dkqj");
							System.out.println(portFee);

						}else if(hasPorts==2) {
							portFee = CalculateUtils.getCoefficient(sysConfigService, avgAchi,"2dkqj");
							System.out.println(portFee);
						}
						BigDecimal addport2=portFee.multiply(new BigDecimal(3)).subtract(thisPort).subtract(lastTotalportfee).subtract(lastLastTotalportfee);
						System.out.println(addport2);
						if(BigDecimal.ZERO.compareTo(addport2)==1) {
							addport2=BigDecimal.ZERO;
						}
						sum=sum.add(addport2);
					}

				}


			}
		}
		return sum;
	}
	/**
	 * 话费补助算法(0:20+0/50/100 1:0/50/100 2:0)
	 */
	public static BigDecimal calculateHF(String month,String employeeId,DataContractDaoXtd dataContractDaoXtd,DictEmployeeService dictEmployeeService,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd) {
		BigDecimal sum=new BigDecimal(0);	
		Map<String, Object> map=new HashMap<>();
		map.put("contractMonth", month.replace("-", ""));
		map.put("employeeId", employeeId);
		int jjjnCountByIdMonth = dataContractDaoXtd.getJJJNCountByIdMonth(map);
		BigDecimal consum=new BigDecimal(jjjnCountByIdMonth);
		/*List<DataContractXtdEntityXtd> xtdByIDMonth = dataContractXtdDaoXtd.getXtdByIDMonth(map);
		for (DataContractXtdEntityXtd dataContractXtdEntityXtd : xtdByIDMonth) {
			BigDecimal everyoneno = dataContractXtdEntityXtd.getEveryoneno();
			if(everyoneno==null) {
				everyoneno=new BigDecimal(0);
			}
			consum=consum.add(everyoneno);
		}*/
		DictEmployeeEntity queryObject = dictEmployeeService.queryObject(employeeId);
		Integer hasorgmobile = queryObject.getHasorgmobile();
		if(hasorgmobile==1) {
			BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, consum, "hfbz");
			sum=coefficient;
		}
		return sum;		
	}
	/**
	 * 改变记录表里的累计业绩方法(放在薪资类型循环外，人员循环里，只执行一次)
	 */
	public static void insertRecord(String month,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd) {
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String jobNo = employee.getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		BigDecimal coff=new BigDecimal("1");
		if("00".equals(jobNo)||"01".equals(jobNo)) {
			coff=new BigDecimal("0.8");
		}
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("employeeId", employeeId);
		List<EmpAllAchievement> contractListByEmpId = dataContractpayDetailServiceXtd.getContractListByEmpId( map);
		boolean flag=false;
		for (EmpAllAchievement empAllAchievement : contractListByEmpId) {
			if(month.replace("-","").equals(empAllAchievement.getContractMonth())) {
				flag=true;
			}
			String contractMonth = empAllAchievement.getContractMonth();
			BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
			Map<String, Object> sqlmap=new HashMap<>();
			sqlmap.put("month", contractMonth);
			sqlmap.put("employeeId",employeeId);
			List<DataEmployeeachiRecordEntityXtd> queryObjectByMonth = dataEmployeeachiRecordServiceXtd.queryObjectByMonth(sqlmap);
			//没有记录那么说明是新单，直接存
			if(queryObjectByMonth.size()==0) {
				BigDecimal totaldx = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi,"dxqj");
				BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi,"tcqj");
				BigDecimal totalportfee = CalculateUtils.getCoefficient(sysConfigService, oneMonthAchi,"dkqj");
				BigDecimal multiply = oneMonthAchi.multiply(coefficient);
				DataEmployeeachiRecordEntityXtd record=new DataEmployeeachiRecordEntityXtd();
				DictEmployeeEntityXtd queryObjectXtd = dictEmployeeServiceXtd.queryObjectXtd(employeeId);
				Integer hasPorts = queryObjectXtd.getHasPorts();
				if(hasPorts==0) {
					totalportfee=new BigDecimal(0);
				}
				record.setEmployeeid(employeeId);
				record.setRecordtime(contractMonth);
				record.setTotalachievement(oneMonthAchi);
				record.setTotalincome(totaldx.multiply(coff));
				record.setTotalextract(multiply.multiply(coff));
				record.setTotalportfee(totalportfee);
				record.setCalTime(month);
				dataEmployeeachiRecordServiceXtd.save(record);
			}else {//这是已有业绩记录的，要借助上次的记录进行更新
				//选取第一个记录
				DataEmployeeachiRecordEntityXtd dataEmployeeachiRecordEntityXtd = queryObjectByMonth.get(0);
				//获得上次总业绩
				BigDecimal totalachievement = dataEmployeeachiRecordEntityXtd.getTotalachievement();				
				//最新累计业绩
				BigDecimal add = oneMonthAchi.add(totalachievement);
				BigDecimal totaldx = CalculateUtils.getCoefficient(sysConfigService, add,"dxqj");
				BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, add,"tcqj");
				BigDecimal totalportfee = CalculateUtils.getCoefficient(sysConfigService, add,"dkqj");
				BigDecimal multiply = add.multiply(coefficient);
				DataEmployeeachiRecordEntityXtd record=new DataEmployeeachiRecordEntityXtd();
				//判断历史表里面是否开端口
				Map<String,Object> hismap=new HashMap<>();
				hismap.put("workNo", employee.getWorkno());
				hismap.put("hisyear", contractMonth.substring(0, 4));
				hismap.put("hismonth", contractMonth.substring(4, 6));
				HisEmployeeEntityXtd hisEmp = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(hismap);
				Integer hasports = hisEmp.getHasports();
				if(hasports==0) {
					totalportfee=new BigDecimal(0);
				}
				record.setEmployeeid(employeeId);
				record.setRecordtime(contractMonth);
				record.setTotalachievement(add);
				record.setTotalincome(totaldx.multiply(coff));
				record.setTotalextract(multiply.multiply(coff));
				record.setTotalportfee(totalportfee);
				record.setCalTime(month);
				dataEmployeeachiRecordServiceXtd.save(record);

			}
		}
		if(!flag&&contractListByEmpId.size()!=0) {
			//说明没有开单,其实可以不存，不涉及回溯
			BigDecimal noAchi=new BigDecimal(0);
			BigDecimal totaldx = CalculateUtils.getCoefficient(sysConfigService, noAchi,"dxqj");
			BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, noAchi,"tcqj");
			BigDecimal totalportfee = CalculateUtils.getCoefficient(sysConfigService, noAchi,"dkqj");
			BigDecimal multiply = noAchi.multiply(coefficient);
			DataEmployeeachiRecordEntityXtd record=new DataEmployeeachiRecordEntityXtd();
			record.setEmployeeid(employeeId);
			record.setRecordtime(month.replace("-",""));
			record.setTotalachievement(noAchi);
			record.setTotalincome(totaldx.multiply(coff));
			record.setTotalextract(multiply.multiply(coff));
			record.setTotalportfee(totalportfee);
			record.setCalTime(month);
			dataEmployeeachiRecordServiceXtd.save(record);
		}
	}

	/**
	 * 计算新人推荐奖励
	 */
	public static BigDecimal calculateTJ(String month,String employeeId,DataRecommendServiceXtd dataRecommendServiceXtd,SysConfigService sysConfigService,DataRecommendRecordServiceXtd dataRecommendRecordServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd) {
		BigDecimal recommendSum=new BigDecimal(0);
		BigDecimal zlsum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String workNo = employee.getWorkno();
		List<DictEmployeeEntityXtd> reEmployeeList = dictEmployeeServiceXtd.queryRecommender(workNo);
		for (DictEmployeeEntityXtd dictEmployeeEntityXtd : reEmployeeList) {
			Date inorgtime = dictEmployeeEntityXtd.getInorgtime();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
			String format = sdf.format(inorgtime);
			//入职时间截取为两位数
			String substring = format.substring(4, 6);
			int start = Integer.parseInt(substring);
			//当前时间截取两位数
			/*String currentMonth=month.substring(5,7);
			int end = Integer.parseInt(currentMonth);*/
			//首月怎么都算，6个月有奖励
			/*if((end-start>0&&end-start<=5)||end+12-start<=5) {*/
			//被推荐人ID
			String reId = dictEmployeeEntityXtd.getId();
			Map<String, Object> map=new HashMap<>();
			map.put("month", month);
			map.put("employeeId", reId);
			List<EmpAllAchievement> zlContractListByEmpId = dataContractpayDetailServiceXtd.getZLContractListByEmpId(map);
			for (EmpAllAchievement empAllAchievement : zlContractListByEmpId) {
				String contractMonth = empAllAchievement.getContractMonth();
				int end = Integer.parseInt(contractMonth.substring(4,6));
				if((end-start>=0&&end-start<=5)||end+12-start<=5) {
					BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
					String value = sysConfigService.getValue("singleColumn.tjr", null);
					zlsum=oneMonthAchi.multiply(new BigDecimal(value)).add(zlsum);
					DataRecommendEntityXtd recommend=new DataRecommendEntityXtd();
					recommend.setCaltime(month);
					recommend.setEmployeeid(reId);
					recommend.setMoney(oneMonthAchi.multiply(new BigDecimal(value)));
					recommend.setRecommenderid(employeeId);
					recommend.setType("DL");
					dataRecommendServiceXtd.save(recommend);
				}
			}
			List<EmpAllAchievement> allAchievementList = dataContractpayDetailServiceXtd.getContractListByEmpId(map);
			for (EmpAllAchievement empAllAchievement : allAchievementList) {
				String contractMonth = empAllAchievement.getContractMonth();
				int end = Integer.parseInt(contractMonth.substring(4,6));
				if((end-start>=0&&end-start<=5)||end+12-start<=5) {
					BigDecimal oneMonthAchi = empAllAchievement.getOneMonthAchi();
					Map<String, Object> mapsql=new HashMap<>();
					mapsql.put("recordTime", contractMonth);
					mapsql.put("recommenderId", employeeId);
					mapsql.put("employeeId", reId);

					List<DataRecommendRecordEntity> queryRecord = dataRecommendRecordServiceXtd.queryRecord(mapsql);
					//找不到为新
					if(queryRecord.size()==0) {
						BigDecimal coefficient = getCoefficient(sysConfigService, oneMonthAchi, "retcqj");
						BigDecimal recommendFee = oneMonthAchi.multiply(coefficient);
						recommendSum=recommendSum.add(recommendFee);
						//这里直接存储
						DataRecommendRecordEntityXtd recommend=new DataRecommendRecordEntityXtd();
						recommend.setEmployeeid(reId);
						recommend.setRecommenderid(employeeId);
						recommend.setTotalachievement(oneMonthAchi);
						recommend.setTotalrecommendfee(recommendFee);
						recommend.setRecordtime(contractMonth);
						recommend.setCalTime(month);
						dataRecommendRecordServiceXtd.save(recommend);

						DataRecommendEntityXtd recommend1=new DataRecommendEntityXtd();
						recommend1.setCaltime(month);
						recommend1.setEmployeeid(reId);
						recommend1.setMoney(recommendFee);
						recommend1.setRecommenderid(employeeId);
						recommend1.setType("MM");
						dataRecommendServiceXtd.save(recommend1);
					}else {
						DataRecommendRecordEntity dataRecommendRecordEntity = queryRecord.get(0);
						//原有记录获取
						BigDecimal totalachievement = dataRecommendRecordEntity.getTotalachievement();
						BigDecimal totalrecommendfee = dataRecommendRecordEntity.getTotalrecommendfee();
						//更新到现累积的业绩
						BigDecimal add = totalachievement.add(oneMonthAchi);
						BigDecimal coefficient = getCoefficient(sysConfigService, add, "retcqj");

						//如今累计发放推荐奖励
						BigDecimal multiply = add.multiply(coefficient);
						BigDecimal subtract = multiply.subtract(totalrecommendfee);
						recommendSum=recommendSum.add(subtract);
						//存储本次数据
						DataRecommendRecordEntityXtd recommend=new DataRecommendRecordEntityXtd();
						recommend.setEmployeeid(reId);
						recommend.setRecommenderid(employeeId);
						recommend.setTotalachievement(add);
						recommend.setTotalrecommendfee(multiply);
						recommend.setRecordtime(contractMonth);
						recommend.setCalTime(month);
						dataRecommendRecordServiceXtd.save(recommend);

						DataRecommendEntityXtd recommend1=new DataRecommendEntityXtd();
						recommend1.setCaltime(month);
						recommend1.setEmployeeid(reId);
						recommend1.setMoney(subtract);
						recommend1.setRecommenderid(employeeId);
						recommend1.setType("MM");
						dataRecommendServiceXtd.save(recommend1);
					}
				}
			}
		}
		return recommendSum.add(zlsum);
	}
	/**
	 * 根据部门编码得到所有旗下主管编码
	 * 调用这个方法要清空result
	 * @return
	 */
	static List<DictDepartmentEntityXtd> result = new ArrayList<DictDepartmentEntityXtd>();
	public static  List<DictDepartmentEntityXtd> getEmployeeByDeptNo(String deptNo,DictDepartmentServiceXtd dictDepartmentServiceXtd){
		List<DictDepartmentEntityXtd> glistByDeptNo = dictDepartmentServiceXtd.getGlistByDeptNo(deptNo);
		for (DictDepartmentEntityXtd dictDepartmentEntityXtd : glistByDeptNo) {
			String childNo = dictDepartmentEntityXtd.getDeptNo();
			if(!("Z".equals(childNo.substring(0, 1)))&&!("z".equals(childNo.substring(0, 1)))) {
				getEmployeeByDeptNo(childNo, dictDepartmentServiceXtd);
			}else {
				result.add(dictDepartmentEntityXtd);
			}
		}
		return result;

	};
	/**
	 * 查询部门编号旗下分行个数，每个分行对应一个分行行长，该行长可能是更高级别，单算人数只要看有几个分行行长即可。往上再算就是重复(适用于分行以上人的计算)
	 */
	static List<DictDepartmentEntityXtd> FHresult = new ArrayList<DictDepartmentEntityXtd>();
	public static  List<DictDepartmentEntityXtd> getFHByDeptNo(String deptNo,DictDepartmentServiceXtd dictDepartmentServiceXtd){

		List<DictDepartmentEntityXtd> glistByDeptNo = dictDepartmentServiceXtd.getGlistByDeptNo(deptNo);
		for (DictDepartmentEntityXtd dictDepartmentEntityXtd : glistByDeptNo) {
			String childNo = dictDepartmentEntityXtd.getDeptNo();
			if(!("F".equals(childNo.substring(0, 1)))&&!("f".equals(childNo.substring(0, 1)))) {
				getFHByDeptNo(childNo, dictDepartmentServiceXtd);
			}else {
				FHresult.add(dictDepartmentEntityXtd);
			}
		}
		return FHresult;

	};
	/**
	 * 根据所有主管部门获取总人数，如果是主管以上还要算自己和由于部门残缺直属他的人
	 * @throws ParseException 
	 * 
	 */
	public static List<DictEmployeeEntityXtd> getAllEmployee(String month,String deptNo,DictEmployeeServiceXtd dictEmployeeServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd) throws ParseException{
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");

		List<DictEmployeeEntityXtd> employeeList=new ArrayList<>();
		//获取所有主管级别的部门类型
		List<DictDepartmentEntityXtd> zDeptList = getEmployeeByDeptNo(deptNo, dictDepartmentServiceXtd);
		//根据部门编码获取员工
		for (DictDepartmentEntityXtd dictDepartmentEntityXtd : zDeptList) {
			//主管的部门编码
			String zDeptNo = dictDepartmentEntityXtd.getDeptNo();
			//根据主管部门编码找所有置业顾问
			List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(zDeptNo);
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryDeptNoXtd) {
				Date inorgtime = dictEmployeeEntityXtd.getInorgtime();
				Date outorgtime = dictEmployeeEntityXtd.getOutorgtime();
				Map<String,Object> map=new HashMap<>();
				map.put("employeeID",dictEmployeeEntityXtd.getId() );
				map.put("month", month);
				String outTime=null;
				if(outorgtime!=null) {
					outTime = sdf.format(outorgtime).substring(0, 7);
				}
				//入职时间在15号之前
				String format = sdf.format(inorgtime);
				String substring = format.substring(0, 7);
				//本月入职
				if(month.equals(substring)) {
					String substring2 = format.substring(8, 10);
					if(Integer.valueOf(substring2)<=15) {
						//本月离职或者未离职
						if(outTime==null||month.equals(outTime)) {
							employeeList.add(dictEmployeeEntityXtd);
						}						
					}else {
						//16号以后根据其预收算人力,合同个数大于0则算人力
						BigDecimal queryAssessmentCountShould = dataContractXtdServiceXtd.queryAssessmentCountShould(map);
						if(queryAssessmentCountShould==null) {
							queryAssessmentCountShould=BigDecimal.ZERO;
						}
						if(queryAssessmentCountShould.compareTo(BigDecimal.ZERO)==1) {
							employeeList.add(dictEmployeeEntityXtd);
						}
					}
				}else {
					//非本月入职，看是不是离职
					if(outTime==null) {
						employeeList.add(dictEmployeeEntityXtd);
					}else if(month.equals(outTime)) {
						String substring2 = sdf.format(outorgtime).substring(8, 10);
						if(Integer.valueOf(substring2)>=6) {
							if(outTime==null||month.equals(outTime)) {
								employeeList.add(dictEmployeeEntityXtd);
							}						
						}else {
							//1-5日开单有预收算人力
							BigDecimal queryAssessmentCountShould = dataContractXtdServiceXtd.queryAssessmentCountShould(map);
							if(queryAssessmentCountShould==null) {
								queryAssessmentCountShould=BigDecimal.ZERO;
							}
							if(queryAssessmentCountShould.compareTo(BigDecimal.ZERO)==1) {
								employeeList.add(dictEmployeeEntityXtd);
							}
						}
					}
				}
			}
			//所有的人不包括1-5日，16-31日离职且没有开单的人，这里是所有的人，要剔除
			/*for (DictEmployeeEntityXtd dictEmployeeEntityXtd : employeeList) {
				Date inorgtime = dictEmployeeEntityXtd.getInorgtime();
				Date outorgtime = dictEmployeeEntityXtd.getOutorgtime();
				String inmonth=month+"-06";
				String outmonth=month+"-15";
				if(outorgtime!=null) {
					Date parse = sdf.parse(outmonth);
					//当月15号以后入职的都要看当月是否有应收.compareTo为1时需要判断
					int compareTo = outorgtime.compareTo(parse);
				}
			}*/
		}
		//直属参数中部门编码的人，这可能是分行本人，还有直属分行的经纪人（主要是主管位置空缺的情况）
		/*List<DictEmployeeEntityXtd> queryDeptNo = dictEmployeeServiceXtd.queryDeptNoXtd(deptNo);
		employeeList.addAll(queryDeptNo);*/
		//获取总人数
		result.clear();
		return employeeList;
	}



	/**
	 * 计算分店直接管理津贴
	 * @throws ParseException 
	 * 
	 */
	public static BigDecimal calculateFDZJ(String month,String employeeId,DataCalculateKService dataCalculateKService,DataContractXtdServiceXtd dataContractXtdServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeService dictEmployeeService,DataBranchachiRecordServiceXtd dataBranchachiRecordServiceXtd,SysConfigService sysConfigService,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		BigDecimal sumFDZJ =new BigDecimal(0);
		BigDecimal K1=new BigDecimal(1);
		BigDecimal K2=new BigDecimal(1);
		BigDecimal K3=new BigDecimal(1);
		BigDecimal K4=new BigDecimal(1);
		String deptNo=null;
		Map<String, Object> map=new HashMap<>();
		DictEmployeeEntity employee = dictEmployeeService.queryObject(employeeId);
		//获得离职时间
		Date outorgtime = employee.getOutorgtime();
		//所有增项
		BigDecimal addFDZJ =BigDecimal.ZERO;
		String jobNo = employee.getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		String name = employee.getName();
		String workno = employee.getWorkno();
		map.put("month", month);
		map.put("branchNo", workno);
		//归属该分店经理的所有买卖单子按签约年月计算的总和
		List<DirAllAchievement> achiListByContractMonth = dataContractpayDetailServiceXtd.getAchiListByContractMonth(map);
		Map<String, Object> deptmap=new HashMap<>();
		deptmap.put("workNo", workno);
		deptmap.put("deptNoFirst", "F");
		//此人的分行
		DictDepartmentEntityXtd dept = dictDepartmentServiceXtd.getDepNo(deptmap);
		if(dept==null) {
			//如果此人被降级，看看他是否在历史表里存在Q职级
			HisDepartmentEntityXtd hisDep = hisDepartmentServiceXtd.getDepNo(deptmap);
			if(hisDep==null) {
				//还找不到，说明不是被降级的
				return BigDecimal.ZERO;
			}
			deptNo=hisDep.getDeptNo();
		}else {
			deptNo = dept.getDeptNo();
		}


		//该员工的分店部门编号
		/*String deptNo = dept.getDeptNo();*/
		//当月此部门旗下所有员工
		List<DictEmployeeEntityXtd> allEmployee = getAllEmployee(month,deptNo, dictEmployeeServiceXtd, dictDepartmentServiceXtd,dataContractXtdServiceXtd);
		//上面方法没算到分店本人，有且只有一人
		int size = allEmployee.size()+1;	
		result.clear();
		//遍历业绩，主要获取年月
		for (DirAllAchievement achi : achiListByContractMonth) {
			//签约年月
			String contractMonth = achi.getContractMonth();
			//如果签约月当月不是分行级别，则不考虑
			if(!(contractMonth.equals(month.replace("-", "")))) {
				Map<String, Object> empmap3=new HashMap<>();
				empmap3.put("workNo", workno);
				empmap3.put("hisyear", contractMonth.substring(0, 4));
				empmap3.put("hismonth", contractMonth.substring(4, 6));
				HisEmployeeEntityXtd queryEmployeeByInOrgTime2 = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(empmap3);
				if(queryEmployeeByInOrgTime2==null) {
					continue;
				}
				String jobNo3 = queryEmployeeByInOrgTime2.getJobno();
				String substring = jobNo3.substring(0, 2);
				if(Integer.parseInt(substring)<7) {
					continue;
				} 
			}												
			BigDecimal oneMonthAchi = achi.getOneMonthAchi();
			Map<String, Object> empmap=new HashMap<>();
			empmap.put("month", contractMonth);
			empmap.put("branchNo", workno);
			//该部门该签单月目前为止开单人数，且已收不为0
			double actSize = 0;
			List<DataEmpAchi> activeEmpByMonth = dataContractpayDetailServiceXtd.getActiveEmpByMonth(empmap);
			for (DataEmpAchi dataEmpAchi : activeEmpByMonth) {
				String empId = dataEmpAchi.getEmployeeID();
				/*boolean judgeEmp = judgeEmp(contractMonth,empId,hisEmployeeServiceXtd,dictEmployeeServiceXtd);*/
				boolean judgeEmp=true;
				double judgeAct = judgeAct(contractMonth, empId, dataContractXtdServiceXtd);
				/*boolean judgeOutEmp = judgeOutEmp(contractMonth, empId,hisEmployeeServiceXtd, dictEmployeeServiceXtd);*/
				boolean judgeOutEmp=true;
				if(judgeEmp) {
					//判断合同月是否有主签约，前面已经对实收为0进行了筛选
					if(judgeOutEmp) {
						actSize=actSize+judgeAct;							
					}
				}
			}
			Map<String, Object> judmap=new HashMap<>();
			judmap.put("recordTime", contractMonth);
			judmap.put("calTime", month);
			judmap.put("branchNo", workno);
			//查看非本月记录，有就是老记录，没有就是新记录
			List<DataBranchachiRecordEntityXtd> listByCaltime = dataBranchachiRecordServiceXtd.getListToCal(judmap);
			if(listByCaltime.size()==0) {
				//新记录
				//看新纪录有没有存
				Map<String, Object> newmap=new HashMap<>();
				newmap.put("recordTime", contractMonth);
				newmap.put("calTime", month);
				newmap.put("branchNo", workno);
				List<DataBranchachiRecordEntityXtd> thisMonthRecord = dataBranchachiRecordServiceXtd.getListByCaltime(newmap);
				if(thisMonthRecord.size()==0) {
					//新纪录没有存，计算之后存储
					//总人数为0
					if(size!=0) {
						//没有记录
						if("071".equals(jobNo)||"072".equals(jobNo)) {
							String value = sysConfigService.getValue("dfhtt", null);
							K1=new BigDecimal(value);
						}else if(!("09".equals(jobNo)||"10".equals(jobNo)/*||"11".equals(jobNo)*/)) {
							//不是高级和资深都是普通
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "fhyjqj", 1);
						}else if("09".equals(jobNo)) {
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "fhyjqj", 2);
						}else if("10".equals(jobNo)) {
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "fhyjqj", 3);
						}/*else if("11".equals(jobNo)) {
								String value = sysConfigService.getValue("dqyfhtt", null);
								K1=new BigDecimal(value);
							}*/
						BigDecimal divide = oneMonthAchi.divide(new BigDecimal(size),4, BigDecimal.ROUND_HALF_UP);
						K2=getCoefficient(sysConfigService, divide, "fhrj");
						BigDecimal act = new BigDecimal(actSize).divide(new BigDecimal(size),4,BigDecimal.ROUND_HALF_UP);
						K3=getCoefficient(sysConfigService, act, "fhhdl");
					}else {
						K2=new BigDecimal(0);
						K3=new BigDecimal(0);
					}					

					String value = sysConfigService.getValue("groupAchievement.fhzjyc", null);
					K4=new BigDecimal(value);
					BigDecimal thisMonthZJ=new BigDecimal(0);
					if("071".equals(jobNo)||"072".equals(jobNo)/*||"11".equals(jobNo)*/) {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("F");
						k.setJobno(jobNo);
						k.setWorkno(workno);
						k.setName(name);
						k.setK1(K1);
						dataCalculateKService.save(k);
						thisMonthZJ=K1.multiply(oneMonthAchi);
					}else {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("F");
						k.setJobno(jobNo);
						k.setWorkno(workno);
						k.setName(name);
						k.setK1(K1);
						k.setK2(K2);
						k.setK3(K3);
						k.setK4(K4);
						dataCalculateKService.save(k);
						thisMonthZJ = K1.multiply(K2).multiply(K3).multiply(K4).multiply(oneMonthAchi);
					}

					sumFDZJ=sumFDZJ.add(thisMonthZJ);
					//计算完毕开始存储
					DataBranchachiRecordEntityXtd branchRecord=new DataBranchachiRecordEntityXtd();
					branchRecord.setBranchno(workno);
					branchRecord.setCaltime(month);
					branchRecord.setPeoplecount(new BigDecimal(size));
					branchRecord.setRecordtime(contractMonth);
					branchRecord.setTotalachievement(oneMonthAchi);
					branchRecord.setTotaldirect(thisMonthZJ);
					dataBranchachiRecordServiceXtd.save(branchRecord);
				}else {
					//新纪录已存
					Map<String, Object> mapp=new HashMap<>();
					mapp.put("recordTime", contractMonth);
					mapp.put("branchNo", workno);
					List<DataBranchachiRecordEntityXtd> listByrecordTime = dataBranchachiRecordServiceXtd.getListByrecordTime(mapp);
					BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
					addFDZJ=addFDZJ.add(totaldirect);
				}
			}else {
				//已有记录			
				//虽然有非本月的记录，还要判断本月有没有记录这个
				Map<String, Object> newmap=new HashMap<>();
				newmap.put("recordTime", contractMonth);
				newmap.put("calTime", month);
				newmap.put("branchNo", workno);
				List<DataBranchachiRecordEntityXtd> thisMonthRecord = dataBranchachiRecordServiceXtd.getListByCaltime(newmap);
				if(thisMonthRecord.size()==0) {
					//没有存，计算之后存储
					//人均业绩
					Map<String, Object> empmap1=new HashMap<>();
					empmap1.put("recordTime", contractMonth);
					empmap1.put("branchNo", workno);
					List<DataBranchachiRecordEntityXtd> listByrecordTime = dataBranchachiRecordServiceXtd.getListByrecordTime(empmap1);
					DataBranchachiRecordEntityXtd dataBranchachiRecordEntityXtd = listByrecordTime.get(0);
					//总人不变
					BigDecimal peoplecount = dataBranchachiRecordEntityXtd.getPeoplecount();
					//上次累计已发直接管理津贴
					BigDecimal totaldirect = dataBranchachiRecordEntityXtd.getTotaldirect();
					BigDecimal totalachievement = dataBranchachiRecordEntityXtd.getTotalachievement();
					//累计业绩
					totalachievement=totalachievement.add(oneMonthAchi);
					//这里的职级可能发生变化，要回溯到当月职级
					Map<String, Object> empmap2=new HashMap<>();
					empmap2.put("workNo", workno);
					empmap2.put("hisyear", contractMonth.substring(0, 4));
					empmap2.put("hismonth", contractMonth.substring(4, 6));
					HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(empmap2);
					String jobNo2 = queryEmployeeByInOrgTime.getJobno();
					if("11.0".equals(jobNo2)) {
						jobNo2="11";
					}
					if("12.0".equals(jobNo2)) {
						jobNo2="12";
					}
					if("13.0".equals(jobNo2)) {
						jobNo2="13";
					}
					if("14.0".equals(jobNo2)) {
						jobNo2="14";
					}
					if("15.0".equals(jobNo2)) {
						jobNo2="15";
					}
					if("16.0".equals(jobNo2)) {
						jobNo2="16";
					}
					if("17.0".equals(jobNo2)) {
						jobNo2="17";
					}
					if("18.0".equals(jobNo2)) {
						jobNo2="18";
					}
					if("071".equals(jobNo2)||"072".equals(jobNo2)) {
						String value = sysConfigService.getValue("dfhtt", null);
						K1=new BigDecimal(value);
					}else if(!("09".equals(jobNo2)||"10".equals(jobNo2))) {
						//不是高级和资深都是普通
						K1=choseCoefficient(sysConfigService, totalachievement, "fhyjqj", 1);
						//这边代区域统提都改为普通
						/*if("11".equals(jobNo2)) {
								BigDecimal choseCoefficient = new BigDecimal(sysConfigService.getValue("dfhtt", null));
								if(K1.compareTo(choseCoefficient)==-1) {
									K1=choseCoefficient;
								}

							}*/
					}else if("09".equals(jobNo2)) {
						K1=choseCoefficient(sysConfigService, totalachievement, "fhyjqj", 2);
					}else if("10".equals(jobNo2)) {
						K1=choseCoefficient(sysConfigService, totalachievement, "fhyjqj", 3);
					}
					BigDecimal divide = totalachievement.divide(peoplecount,4, BigDecimal.ROUND_HALF_UP);
					K2=getCoefficient(sysConfigService, divide, "fhrj");
					//活动率
					BigDecimal act = new BigDecimal(actSize).divide(peoplecount,4, BigDecimal.ROUND_HALF_UP);
					K3=getCoefficient(sysConfigService, act, "fhhdl");
					String value = sysConfigService.getValue("groupAchievement.fhzjyc", null);
					K4=new BigDecimal(value);
					BigDecimal thisMonthZJ=new BigDecimal(0);
					if("071".equals(jobNo2)||"072".equals(jobNo2)/*||"11".equals(jobNo2)*/) {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("F");
						k.setJobno(jobNo);
						k.setWorkno(workno);
						k.setName(name);
						k.setK1(K1);
						dataCalculateKService.save(k);
						thisMonthZJ=K1.multiply(totalachievement);
					}else {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("F");
						k.setJobno(jobNo);
						k.setWorkno(workno);
						k.setName(name);
						k.setK1(K1);
						k.setK2(K2);
						k.setK3(K3);
						k.setK4(K4);
						dataCalculateKService.save(k);
						thisMonthZJ =  K1.multiply(K2).multiply(K3).multiply(K4).multiply(totalachievement);
					}

					addFDZJ=addFDZJ.add(thisMonthZJ).subtract(totaldirect);
					//计算完毕开始存储
					DataBranchachiRecordEntityXtd branchRecord=new DataBranchachiRecordEntityXtd();
					branchRecord.setBranchno(workno);
					branchRecord.setCaltime(month);
					branchRecord.setPeoplecount(peoplecount);
					branchRecord.setRecordtime(contractMonth);
					branchRecord.setTotalachievement(totalachievement);
					branchRecord.setTotaldirect(thisMonthZJ);
					dataBranchachiRecordServiceXtd.save(branchRecord);
				}else {
					//纪录已存.获取新月直接减去旧月
					Map<String, Object> empmap1=new HashMap<>();
					empmap1.put("recordTime", contractMonth);
					empmap1.put("branchNo", workno);
					List<DataBranchachiRecordEntityXtd> listByrecordTime = dataBranchachiRecordServiceXtd.getListByrecordTime(empmap1);
					if(listByrecordTime.size()>1) {
						BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
						BigDecimal totaldirectold = listByrecordTime.get(1).getTotaldirect();
						BigDecimal subtract = totaldirect.subtract(totaldirectold);
						addFDZJ=addFDZJ.add(subtract);
					}else {
						BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
						addFDZJ=addFDZJ.add(totaldirect);
					}

				}

			}
		}
		if(outorgtime!=null) {
			System.out.println(addFDZJ);
			addFDZJ=BigDecimal.ZERO;
			
		}
		sumFDZJ=sumFDZJ.add(addFDZJ);
		return sumFDZJ.setScale(4,BigDecimal.ROUND_HALF_UP);

	}
	/**
	 * 分行间接管理津贴
	 * @throws ParseException 
	 */
	public static BigDecimal calculateFHJJ(String month,String employeeId,DataCalculateKService dataCalculateKService,DataContractXtdServiceXtd dataContractXtdServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeService dictEmployeeService,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataBranchachiRecordServiceXtd dataBranchachiRecordServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		BigDecimal FHJJsum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String workno = employee.getWorkno();
		Map<String, Object> map =new HashMap<>();
		map.put("branchBredNo", workno);
		List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(map);
		if(queryBredNo.size()!=0) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryBredNo) {
				String bredworkNo = dictEmployeeEntityXtd.getWorkno();
				Map<String, Object> deptmap=new HashMap<>();
				deptmap.put("workNo", bredworkNo);
				deptmap.put("deptNoFirst", "F");
				//此人的分行
				DictDepartmentEntityXtd dept = dictDepartmentServiceXtd.getDepNo(deptmap);
				//不为空说明此人有管辖的分行
				if(dept!=null) {
					String id = dictEmployeeEntityXtd.getId();
					BigDecimal calculateFHTD = calculateTDDL(month, id, "branchNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String fhvalue = sysConfigService.getValue("singleColumn.fh", null);
					//单列提成部分
					BigDecimal fhall = calculateFHTD.multiply(new BigDecimal(fhvalue));
					BigDecimal calculateFDZJ = calculateFDZJ(month, id,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd,dictEmployeeService, dataBranchachiRecordServiceXtd, sysConfigService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);					
					FHJJsum=FHJJsum.add(calculateFDZJ).add(fhall);
				}
			}
		}

		//间接提成系数
		String value = sysConfigService.getValue("groupAchievement.fhjjyc", null);
		FHJJsum=FHJJsum.multiply(new BigDecimal(value));
		return FHJJsum.setScale(4,BigDecimal.ROUND_HALF_UP);

	}

	/**
	 * 根据主管编号和工资计算月份，算出这个主管的直接管理津贴
	 * 
	 */
	public static BigDecimal calculateZGZJJT(String month,String workNo,DataCalculateKService dataCalculateKService,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataDirectorachiRecordServiceXtd dataDirectorachiRecordServiceXtd,SysConfigService sysConfigService,HisDepartmentServiceXtd hisDepartmentServiceXtd){

		DictEmployeeEntity employee = dictEmployeeServiceXtd.getListByWorkNo(workNo);
		//获得离职时间
		Date outorgtime = employee.getOutorgtime();
		if("f8eda708077b4ea0a6ea7b40b2d2f2de".equals(employee.getId())) {
			System.out.println(workNo);
		}
		String depNo=null;
		String name = employee.getName();
		BigDecimal sum=new BigDecimal(0);
		//增项
		BigDecimal addZGJJ=BigDecimal.ZERO;
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("directorNo", workNo);		
		String monthnew = month.replace("-", "");
		Map<String, Object> depMap=new HashMap<>();
		depMap.put("workNo", workNo);
		depMap.put("deptNoFirst", "Z");
		//通过月份和主管编号，得到当月主管按月份排序的业绩；
		List<DirAllAchievement> contractListByDirectorId = dataContractpayDetailServiceXtd.getAchiListByContractMonth(map);
		DictDepartmentEntityXtd dep = dictDepartmentServiceXtd.getDepNo(depMap);
		//如果要计算但是找不到此人的区域，说明是被降级了或者没被降级的更低级
		if(dep==null) {
			//如果此人被降级，看看他是否在历史表里存在Q职级
			HisDepartmentEntityXtd hisDep = hisDepartmentServiceXtd.getDepNo(depMap);
			if(hisDep==null) {
				//还找不到，说明不是被降级的
				return BigDecimal.ZERO;
			}
			depNo=hisDep.getDeptNo();
		}else {
			depNo = dep.getDeptNo();
		}

		//通过部门标号，得到其组成员
		List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(depNo);
		int allSize=queryDeptNoXtd.size();
		for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryDeptNoXtd) {
			boolean judgeEmp = judgeEmp(month,dictEmployeeEntityXtd.getId(),hisEmployeeServiceXtd,dictEmployeeServiceXtd,dataContractXtdServiceXtd);
			if(!judgeEmp) {
				allSize--;
			}
		}
		String jobNo = dictEmployeeServiceXtd.querySingleXtd(workNo).getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		//判断，如果主管同时也是分店经理，则人数加一，不是得直接得到主管团队人数
		BigDecimal hasPeople = new BigDecimal(0);
		if(jobNo.equals("071")||jobNo.equals("072")||jobNo.equals("08")||jobNo.equals("09")||jobNo.equals("10")) {
			hasPeople = new BigDecimal(allSize+1);
		}else {
			hasPeople = new BigDecimal(allSize);
		}
		for (DirAllAchievement dirAllAchievement : contractListByDirectorId) {
			String contractMonth = dirAllAchievement.getContractMonth();
			BigDecimal oneMonthAchi = dirAllAchievement.getOneMonthAchi();	
			Map<String, Object> map2=new HashMap<>();
			map2.put("month", contractMonth);
			map2.put("directorNo", workNo);
			//通过月份和主管编号，得到这个主管所给月份的累计业绩、直接管理津贴的情况
			List<DataDirectorachiRecordEntityXtd> queryObjectByMonth = dataDirectorachiRecordServiceXtd.queryObjectByMonth(map2);
			//通过月份和主管编号，得到所给月份月这个组累计开单有实收的人数
			double actSize = 0;
			List<DataEmpAchi> activeEmpByMonth = dataContractpayDetailServiceXtd.getActiveEmpByMonth(map2);
			for (DataEmpAchi dataEmpAchi : activeEmpByMonth) {
				String empId2 = dataEmpAchi.getEmployeeID();
				/*boolean judgeEmp = judgeEmp(contractMonth,empId,hisEmployeeServiceXtd,dictEmployeeServiceXtd);*/
				boolean judgeEmp=true;
				double judgeAct = judgeAct(contractMonth, empId2, dataContractXtdServiceXtd);
				/*boolean judgeOutEmp = judgeOutEmp(contractMonth, empId,hisEmployeeServiceXtd, dictEmployeeServiceXtd);*/
				boolean judgeOutEmp=true;				
				if(judgeEmp) {
					//判断合同月是否有主签约，前面已经对实收为0进行了筛选
					if(judgeOutEmp) {
						actSize=actSize+judgeAct;
					}

				}
			}
			BigDecimal activePeople = new BigDecimal(actSize);
			//为空，则为当月新业绩，并且未计算
			if(queryObjectByMonth.size()==0) {
				//主管团队人均业绩
				BigDecimal zgrjyj = oneMonthAchi.divide(hasPeople,4, BigDecimal.ROUND_HALF_UP);
				//主管团队活动率
				BigDecimal zghdl = activePeople.divide(hasPeople,4, BigDecimal.ROUND_HALF_UP);
				//主管团队人均业绩系数
				BigDecimal coefficient = new BigDecimal(0);
				if(/*!("05".equals(jobNo)||"06".equals(jobNo))*/"04".equals(jobNo)) {
					//普通主管
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj, "zgrjyjqj", 1);
				}else if("05".equals(jobNo)) {
					//高级主管
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj, "zgrjyjqj", 2);
				}else if("06".equals(jobNo)) {
					//资深主管
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj, "zgrjyjqj", 3);
				}else {
					coefficient=BigDecimal.ZERO;
				}
				//主管团队活动率系数
				BigDecimal coefficient2 = CalculateUtils.getCoefficient(sysConfigService, zghdl,"zghdl");
				//主管团队直接育成关系系数
				String value = sysConfigService.getValue("groutAchievement.zgzjycgxxs",null);
				BigDecimal coefficient3 = new BigDecimal(value);
				DataCalculateKEntity k=new DataCalculateKEntity();
				k.setCaltime(month);
				k.setRecordtime(contractMonth);
				k.setDeptno("Z");
				k.setJobno(jobNo);
				k.setWorkno(workNo);
				k.setName(name);
				k.setK1(coefficient);
				k.setK2(coefficient2);
				k.setK3(coefficient3);
				dataCalculateKService.save(k);
				BigDecimal multiply = oneMonthAchi.multiply(coefficient).multiply(coefficient2).multiply(coefficient3);
				sum=sum.add(multiply);
				//计算完成，保存记录
				DataDirectorachiRecordEntityXtd thisDirector = new DataDirectorachiRecordEntityXtd();
				thisDirector.setDirectorno(workNo);
				thisDirector.setRecordtime(contractMonth);
				thisDirector.setTotalachievement(oneMonthAchi);
				thisDirector.setTotalincome(multiply);
				thisDirector.setPeopleCount(hasPeople);
				thisDirector.setCalTime(month);
				dataDirectorachiRecordServiceXtd.saveXtd(thisDirector);
			}else if(contractMonth.equals(monthnew)) {
				//当月新业绩，已经计算过了，直接调用
				DataDirectorachiRecordEntityXtd dataDirectorachiRecordEntityXtd = queryObjectByMonth.get(0);
				BigDecimal income = dataDirectorachiRecordEntityXtd.getTotalincome();
				sum = sum.add(income);
			}else {
				//获得之前记录的最新的数据
				DataDirectorachiRecordEntityXtd dataDirectorachiRecordEntityXtd = queryObjectByMonth.get(0);
				//获得总业绩
				BigDecimal totalachievement = dataDirectorachiRecordEntityXtd.getTotalachievement();
				//获取累计直接管理津贴
				BigDecimal totalincome = dataDirectorachiRecordEntityXtd.getTotalincome();
				//获取团队人数
				BigDecimal peopleCount = dataDirectorachiRecordEntityXtd.getPeopleCount();
				//获取该条记录的计算时间
				String calTime = dataDirectorachiRecordEntityXtd.getCalTime();			
				if (!calTime.equals(month)) {
					//老记录，没计算过，计算后保存
					BigDecimal add = oneMonthAchi.add(totalachievement);
					BigDecimal zgrjyj2 = add.divide(peopleCount,4, BigDecimal.ROUND_HALF_UP);
					BigDecimal coefficient4 = new BigDecimal(0);
					
					
					//这里的职级可能发生变化，要回溯到当月职级
					Map<String, Object> empmap2=new HashMap<>();
					empmap2.put("workNo", workNo);
					empmap2.put("hisyear", contractMonth.substring(0, 4));
					empmap2.put("hismonth", contractMonth.substring(4, 6));
					HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(empmap2);
					String jobNo2 = queryEmployeeByInOrgTime.getJobno();
					if("11.0".equals(jobNo2)) {
						jobNo2="11";
					}
					if("12.0".equals(jobNo2)) {
						jobNo2="12";
					}
					if("13.0".equals(jobNo2)) {
						jobNo2="13";
					}
					if("14.0".equals(jobNo2)) {
						jobNo2="14";
					}
					if("15.0".equals(jobNo2)) {
						jobNo2="15";
					}
					if("16.0".equals(jobNo2)) {
						jobNo2="16";
					}
					if("17.0".equals(jobNo2)) {
						jobNo2="17";
					}
					if("18.0".equals(jobNo2)) {
						jobNo2="18";
					}

					
					if(/*!("05".equals(jobNo)||"06".equals(jobNo))*/"04".equals(jobNo2)) {
						//普通主管
						coefficient4=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj2, "zgrjyjqj", 1);
					}else if("05".equals(jobNo2)) {
						//高级主管
						coefficient4=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj2, "zgrjyjqj", 2);
					}else if("06".equals(jobNo2)) {
						//资深主管
						coefficient4=CalculateUtils.choseCoefficient(sysConfigService, zgrjyj2, "zgrjyjqj", 3);
					}else {
						coefficient4=BigDecimal.ZERO;
					}
					BigDecimal zghdl2 = activePeople.divide(peopleCount,4,BigDecimal.ROUND_HALF_UP);
					BigDecimal coefficient5 = CalculateUtils.getCoefficient(sysConfigService, zghdl2,"zghdl");
					String value = sysConfigService.getValue("groutAchievement.zgzjycgxxs",null);
					BigDecimal coefficient6 = new BigDecimal(value);
					BigDecimal multiply2 = add.multiply(coefficient4).multiply(coefficient5).multiply(coefficient6);
					DataCalculateKEntity k=new DataCalculateKEntity();
					k.setCaltime(month);
					k.setRecordtime(contractMonth);
					k.setDeptno("Z");
					k.setJobno(jobNo2);
					k.setWorkno(workNo);
					k.setName(name);
					k.setK1(coefficient4);
					k.setK2(coefficient5);
					k.setK3(coefficient6);
					dataCalculateKService.save(k);
					BigDecimal multiply3=multiply2.subtract(totalincome);
					addZGJJ=addZGJJ.add(multiply3);
					//计算完成，保存记录
					dataDirectorachiRecordEntityXtd.setTotalachievement(add);
					dataDirectorachiRecordEntityXtd.setTotalincome(multiply2);
					dataDirectorachiRecordEntityXtd.setCalTime(month);
					dataDirectorachiRecordServiceXtd.saveXtd(dataDirectorachiRecordEntityXtd);
				}else {
					//老记录，已经计算过，直接调用
					if(queryObjectByMonth.size()>1) {
						BigDecimal income2 = queryObjectByMonth.get(0).getTotalincome();
						BigDecimal income2old = queryObjectByMonth.get(1).getTotalincome();
						BigDecimal subtract = income2.subtract(income2old);
						addZGJJ=addZGJJ.add(subtract);
					}else {
						BigDecimal income2 = queryObjectByMonth.get(0).getTotalincome();
						addZGJJ=addZGJJ.add(income2);
					}

				}
			}
		}
		//离职不享受增项
		if(outorgtime!=null) {
			System.out.println(addZGJJ);
			addZGJJ=BigDecimal.ZERO;
		}
		sum=sum.add(addZGJJ);
		return sum;

	}

	/**
	 * 根据主管编号和工资计算月份，算出这个主管的间接管理津贴
	 * 
	 */
	public static BigDecimal calculateZGJJJT(String month,String workNo,DataCalculateKService dataCalculateKService,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataDirectorachiRecordServiceXtd dataDirectorachiRecordServiceXtd,SysConfigService sysConfigService,HisDepartmentServiceXtd hisDepartmentServiceXtd) {
		BigDecimal zgjjsum=new BigDecimal(0);
		List<DictEmployeeEntityXtd> queryDirectorBredNoXtd = dictEmployeeServiceXtd.queryDirectorBredNoXtd(workNo);
		//不为空，则有被育成人
		if(queryDirectorBredNoXtd.size()!=0) {
			//循环计算被育成人的直接管理津贴
			for(DictEmployeeEntityXtd dictEmployeeEntityXtd : queryDirectorBredNoXtd) {
				String directorWorkNo = dictEmployeeEntityXtd.getWorkno();
				String id = dictEmployeeEntityXtd.getId();
				BigDecimal sumsingle = CalculateUtils.calculateZGZJJT(month,directorWorkNo,dataCalculateKService,hisEmployeeServiceXtd,dataContractXtdServiceXtd, dataContractpayDetailServiceXtd, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataDirectorachiRecordServiceXtd, sysConfigService,hisDepartmentServiceXtd);
				BigDecimal calculateZGTD = calculateTDDL(month, id, "directorNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
				String zgvalue = sysConfigService.getValue("singleColumn.zg", null);
				//单列提成部分
				BigDecimal zgall = calculateZGTD.multiply(new BigDecimal(zgvalue));
				zgjjsum = zgjjsum.add(sumsingle).add(zgall);
			}
			String value = sysConfigService.getValue("groutAchievement.zgjjycgxxs",null);
			BigDecimal coefficient = new BigDecimal(value);
			zgjjsum = zgjjsum.multiply(coefficient);
		}
		return zgjjsum;
	}
	/**
	 * 根据区域经理编号和工资计算月份，算出这个区域经理的直接管理津贴
	 * @throws ParseException 
	 * 
	 */
	public static BigDecimal calculateQYZJJT(String month,String workNo,DataCalculateKService dataCalculateKService,DataContractXtdServiceXtd dataContractXtdServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataAreaachiRecordServiceXtd dataAreaachiRecordServiceXtd,SysConfigService sysConfigService,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException{
		BigDecimal sum=new BigDecimal(0);
		BigDecimal addQYZJ=BigDecimal.ZERO;
		String depNo=null;
		DictEmployeeEntity employee = dictEmployeeServiceXtd.getListByWorkNo(workNo);	
		Date outorgtime = employee.getOutorgtime();
		String name = employee.getName();
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put("areaNo", workNo);		
		String monthnew = month.replace("-", "");
		Map<String, Object> depMap=new HashMap<>();
		depMap.put("workNo", workNo);
		depMap.put("deptNoFirst", "Q");
		//通过月份和区域经理编号，得到当月区域经理按月份排序的业绩；
		List<DirAllAchievement> contractListByDirectorId = dataContractpayDetailServiceXtd.getAchiListByContractMonth(map);
		DictDepartmentEntityXtd dep = dictDepartmentServiceXtd.getDepNo(depMap);
		//如果要计算但是找不到此人的区域，说明是被降级了或者没被降级的更低级
		if(dep==null) {
			//如果此人被降级，看看他是否在历史表里存在Q职级
			HisDepartmentEntityXtd hisDep = hisDepartmentServiceXtd.getDepNo(depMap);
			if(hisDep==null) {
				//还找不到，说明不是被降级的
				return BigDecimal.ZERO;
			}
			depNo=hisDep.getDeptNo();
		}else {
			depNo = dep.getDeptNo();
		}

		String jobNo = dictEmployeeServiceXtd.querySingleXtd(workNo).getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		//当月此部门旗下所有员工
		List<DictEmployeeEntityXtd> allEmployee = getAllEmployee(month,depNo, dictEmployeeServiceXtd, dictDepartmentServiceXtd,dataContractXtdServiceXtd);
		int size = allEmployee.size();
		List<DictDepartmentEntityXtd> fhByDeptNo = getFHByDeptNo(depNo, dictDepartmentServiceXtd);
		//仅主管及主管以下都计算到了，而主管及以上没有。找到所有分行。
		size+=fhByDeptNo.size();
		BigDecimal hasPeople = new BigDecimal(size);
		result.clear();
		FHresult.clear();
		/*if(jobNo.equals("11")) {
			//这边没有不算租赁，没有存放在record表
			BigDecimal sumAchi=new BigDecimal(0);
			List<DirAllAchievement> allAchiByContractMonth= dataContractpayDetailServiceXtd.getAchiListByContractMonth(map);
			for (DirAllAchievement dirAllAchievement : allAchiByContractMonth) {
				BigDecimal oneMonthAchi = dirAllAchievement.getOneMonthAchi();
				sumAchi=sumAchi.add(oneMonthAchi);
			}
			String value = sysConfigService.getValue("areaAchievement.dqyzjyc", null);
			BigDecimal dqyzjjtxs = new BigDecimal(value);
			sum = sumAchi.multiply(dqyzjjtxs);
		}else {*/
		for (DirAllAchievement dirAllAchievement : contractListByDirectorId) {
			/*BigDecimal sumAchi=new BigDecimal(0);*/
			BigDecimal direct=new BigDecimal(0);
			String contractMonth = dirAllAchievement.getContractMonth();
			BigDecimal oneMonthAchi = dirAllAchievement.getOneMonthAchi();	
			Map<String, Object> map2=new HashMap<>();
			map2.put("month", contractMonth);
			map2.put("areaNo", workNo);
			//通过月份和区域经理编号，得到这个区域经理所给月份的累计业绩、直接管理津贴的情况
			List<DataAreaachiRecordEntityXtd> queryObjectByMonth = dataAreaachiRecordServiceXtd.queryObjectByMonth(map2);
			//通过月份和区域经理编号，得到所给月份月这个组累计开单有实收的人数
			double actSize = 0;
			List<DataEmpAchi> activeEmpByMonth = dataContractpayDetailServiceXtd.getActiveEmpByMonth(map2);
			for (DataEmpAchi dataEmpAchi : activeEmpByMonth) {
				String empId2 = dataEmpAchi.getEmployeeID();
				/*boolean judgeEmp = judgeEmp(contractMonth,empId2,hisEmployeeServiceXtd,dictEmployeeServiceXtd);
				double judgeAct = judgeAct(contractMonth, empId2, dataContractXtdServiceXtd);
				boolean judgeOutEmp = judgeOutEmp(contractMonth, empId2,hisEmployeeServiceXtd, dictEmployeeServiceXtd);*/
				/*boolean judgeEmp = judgeEmp(contractMonth,empId,hisEmployeeServiceXtd,dictEmployeeServiceXtd);*/
				boolean judgeEmp=true;
				double judgeAct = judgeAct(contractMonth, empId2, dataContractXtdServiceXtd);
				/*boolean judgeOutEmp = judgeOutEmp(contractMonth, empId,hisEmployeeServiceXtd, dictEmployeeServiceXtd);*/
				boolean judgeOutEmp=true;
				if(judgeEmp) {
					//判断合同月是否有主签约，前面已经对实收为0进行了筛选
					if(judgeOutEmp) {
						actSize=actSize+judgeAct;
					}

				}
			}
			BigDecimal activePeople = new BigDecimal(actSize);
			//为空，则为当月新业绩，并且未计算
			if(queryObjectByMonth.size()==0) {
				//区域经理团队人均业绩
				BigDecimal qyrjyj = oneMonthAchi.divide(hasPeople,4, BigDecimal.ROUND_HALF_UP);
				//区域经理团队活动率
				BigDecimal qyhdl = activePeople.divide(hasPeople,4, BigDecimal.ROUND_HALF_UP);
				//区域经理团队业绩系数
				BigDecimal coefficient = new BigDecimal(0);
				if(jobNo.equals("11")) {
					//这边没有不算租赁，没有存放在record表																				
					String value = sysConfigService.getValue("areaAchievement.dqyzjyc", null);
					coefficient = new BigDecimal(value);

				}else if(!("13".equals(jobNo)||"14".equals(jobNo))) {
					//普通区域经理
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, oneMonthAchi, "qyyj", 1);
				}else if("13".equals(jobNo)) {
					//高级区域经理
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, oneMonthAchi, "qyyj", 2);
				}else if("14".equals(jobNo)) {
					//资深区域经理
					coefficient=CalculateUtils.choseCoefficient(sysConfigService, oneMonthAchi, "qyyj", 3);
				}
				//区域经理团队人均业绩系数
				BigDecimal coefficient2 = CalculateUtils.getCoefficient(sysConfigService, qyrjyj, "qyrjyj");
				//区域经理团队活动率系数
				BigDecimal coefficient3 = CalculateUtils.getCoefficient(sysConfigService, qyhdl,"qyhdl");
				//区域经理团队直接育成关系系数
				String value = sysConfigService.getValue("areaAchievement.qyzjyc",null);
				BigDecimal coefficient4 = new BigDecimal(value);
				if(jobNo.equals("11")) {
					direct = oneMonthAchi.multiply(coefficient);
					DataCalculateKEntity k=new DataCalculateKEntity();
					k.setCaltime(month);
					k.setRecordtime(contractMonth);
					k.setDeptno("Q");
					k.setJobno(jobNo);
					k.setWorkno(workNo);
					k.setName(name);
					k.setK1(coefficient);
					dataCalculateKService.save(k);
					sum=sum.add(direct);
				}else {
					DataCalculateKEntity k=new DataCalculateKEntity();
					k.setCaltime(month);
					k.setRecordtime(contractMonth);
					k.setDeptno("Q");
					k.setJobno(jobNo);
					k.setWorkno(workNo);
					k.setName(name);
					k.setK1(coefficient);
					k.setK2(coefficient2);
					k.setK3(coefficient3);
					k.setK4(coefficient4);
					dataCalculateKService.save(k);
					direct = oneMonthAchi.multiply(coefficient).multiply(coefficient2).multiply(coefficient3).multiply(coefficient4);
					sum=sum.add(direct);
				}
				//计算完成，保存记录
				DataAreaachiRecordEntityXtd thisArea = new DataAreaachiRecordEntityXtd();

				thisArea.setAreano(workNo);
				thisArea.setRecordtime(contractMonth);
				thisArea.setTotalachievement(oneMonthAchi);
				thisArea.setTotaldirect(direct);
				thisArea.setPeoplecount(hasPeople);
				thisArea.setCaltime(month);
				dataAreaachiRecordServiceXtd.saveXtd(thisArea);
				//保存当月收取的间接管理津贴
				DataMonthdirectEntityXtd monthdir=new DataMonthdirectEntityXtd();
				monthdir.setWorkno(workNo);
				monthdir.setAreano(depNo);
				monthdir.setCalmonth(month);
				monthdir.setBasicmonth(contractMonth);
				monthdir.setDirectmoney(direct);
				dataMonthdirectServiceXtd.save(monthdir);



			}else if(contractMonth.equals(monthnew)) {
				//当月新业绩，已经计算过了，直接调用
				DataAreaachiRecordEntityXtd dataAreaachiRecordEntityXtd = queryObjectByMonth.get(0);
				BigDecimal income = dataAreaachiRecordEntityXtd.getTotaldirect();
				sum = sum.add(income);
			}else {
				//活得之前记录的最新的数据
				DataAreaachiRecordEntityXtd dataAreaachiRecordEntityXtd = queryObjectByMonth.get(0);
				//获得总业绩
				BigDecimal totalachievement = dataAreaachiRecordEntityXtd.getTotalachievement();
				//获取累计直接管理津贴
				BigDecimal totalincome = dataAreaachiRecordEntityXtd.getTotaldirect();
				//获取团队人数
				BigDecimal peopleCount = dataAreaachiRecordEntityXtd.getPeoplecount();
				//获取该条记录的计算时间
				String calTime = dataAreaachiRecordEntityXtd.getCaltime();		
				if (!calTime.equals(month)) {
					//老记录，没计算过，计算后保存
					BigDecimal add = oneMonthAchi.add(totalachievement);
					BigDecimal qyrjyj2 = add.divide(peopleCount,4, BigDecimal.ROUND_HALF_UP);
					BigDecimal qyhdl2 = activePeople.divide(peopleCount,4, BigDecimal.ROUND_HALF_UP);
					BigDecimal coefficient5 = new BigDecimal(0);
					Map<String, Object> empmap2=new HashMap<>();
					empmap2.put("workNo", workNo);
					empmap2.put("hisyear", contractMonth.substring(0, 4));
					empmap2.put("hismonth", contractMonth.substring(4, 6));
					HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(empmap2);
					String jobNo2 = queryEmployeeByInOrgTime.getJobno();
					if("11.0".equals(jobNo2)) {
						jobNo2="11";
					}
					if("12.0".equals(jobNo2)) {
						jobNo2="12";
					}
					if("13.0".equals(jobNo2)) {
						jobNo2="13";
					}
					if("14.0".equals(jobNo2)) {
						jobNo2="14";
					}
					if("15.0".equals(jobNo2)) {
						jobNo2="15";
					}
					if("16.0".equals(jobNo2)) {
						jobNo2="16";
					}
					if("17.0".equals(jobNo2)) {
						jobNo2="17";
					}
					if("18.0".equals(jobNo2)) {
						jobNo2="18";
					}
					if("11".equals(jobNo2)) {
						String value = sysConfigService.getValue("areaAchievement.dqyzjyc", null);
						coefficient5 = new BigDecimal(value);
					}else if(!("13".equals(jobNo2)||"14".equals(jobNo2))) {
						//普通区域经理
						coefficient5=CalculateUtils.choseCoefficient(sysConfigService, add, "qyyj", 1);
					}else if("13".equals(jobNo2)) {
						//高级区域经理
						coefficient5=CalculateUtils.choseCoefficient(sysConfigService, add, "qyyj", 2);
					}else if("14".equals(jobNo2)) {
						//资深区域经理
						coefficient5=CalculateUtils.choseCoefficient(sysConfigService, add, "qyyj", 3);
					}
					//区域经理团队人均业绩系数
					BigDecimal coefficient6 = CalculateUtils.getCoefficient(sysConfigService, qyrjyj2, "qyrjyj");
					//区域经理团队活动率系数
					BigDecimal coefficient7 = CalculateUtils.getCoefficient(sysConfigService, qyhdl2,"qyhdl");
					String value = sysConfigService.getValue("areaAchievement.qyzjyc",null);
					BigDecimal coefficient8 = new BigDecimal(value);

					BigDecimal thisMonthZJ=new BigDecimal(0);
					if("11".equals(jobNo2)) {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("Q");
						k.setJobno(jobNo);
						k.setWorkno(workNo);
						k.setName(name);
						k.setK1(coefficient5);

						dataCalculateKService.save(k);
						thisMonthZJ=coefficient5.multiply(add);
					}else {
						DataCalculateKEntity k=new DataCalculateKEntity();
						k.setCaltime(month);
						k.setRecordtime(contractMonth);
						k.setDeptno("Q");
						k.setJobno(jobNo);
						k.setWorkno(workNo);
						k.setName(name);
						k.setK1(coefficient5);
						k.setK2(coefficient6);
						k.setK3(coefficient7);
						k.setK4(coefficient8);
						dataCalculateKService.save(k);
						thisMonthZJ = coefficient5.multiply(coefficient6).multiply(coefficient7).multiply(coefficient8).multiply(add);
					}


					BigDecimal multiply3=thisMonthZJ.subtract(totalincome);
					addQYZJ=addQYZJ.add(multiply3);
					//计算完成，保存记录
					dataAreaachiRecordEntityXtd.setTotalachievement(add);
					dataAreaachiRecordEntityXtd.setTotaldirect(thisMonthZJ);
					dataAreaachiRecordEntityXtd.setCaltime(month);
					dataAreaachiRecordServiceXtd.saveXtd(dataAreaachiRecordEntityXtd);
					//保存当月收取的间接管理津贴
					DataMonthdirectEntityXtd monthdir=new DataMonthdirectEntityXtd();
					monthdir.setWorkno(workNo);
					monthdir.setAreano(depNo);
					monthdir.setCalmonth(month);
					monthdir.setBasicmonth(contractMonth);
					monthdir.setDirectmoney(multiply3);
					dataMonthdirectServiceXtd.save(monthdir);
				}else {
					//老记录，已经计算过，直接调用
					if(queryObjectByMonth.size()>1) {
						BigDecimal income2 = queryObjectByMonth.get(0).getTotaldirect();
						BigDecimal income2old = queryObjectByMonth.get(1).getTotaldirect();
						BigDecimal subtract = income2.subtract(income2old);
						addQYZJ=addQYZJ.add(subtract);
					}else {
						BigDecimal income2 = queryObjectByMonth.get(0).getTotaldirect();
						addQYZJ=addQYZJ.add(income2);
					}

				}
			}
		}
		//离职不享受增项
				if(outorgtime!=null) {
					System.out.println(addQYZJ);
					addQYZJ=BigDecimal.ZERO;
				}
				sum=sum.add(addQYZJ);				
		/*}*/
		return sum;
	}
	/**
	 * 根据区域经理编号和工资计算月份，算出这个区域经理的间接管理津贴
	 * @throws ParseException 
	 * 
	 */
	public static BigDecimal calculateQYJJJT(String month,String workNo,DataCalculateKService dataCalculateKService,DataContractXtdServiceXtd dataContractXtdServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataDirectorachiRecordServiceXtd dataDirectorachiRecordServiceXtd,DataAreaachiRecordServiceXtd dataAreaachiRecordServiceXtd,SysConfigService sysConfigService,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		BigDecimal qyjjsum=new BigDecimal(0);
		List<DictEmployeeEntityXtd> queryAreaBredNoXtd = dictEmployeeServiceXtd.queryAreaBredNoXtd(workNo);
		//不为空，则有被育成人
		if(queryAreaBredNoXtd.size()!=0) {
			//循环计算被育成人的直接管理津贴
			for(DictEmployeeEntityXtd dictEmployeeEntityXtd : queryAreaBredNoXtd) {
				String areaWorkNo = dictEmployeeEntityXtd.getWorkno();
				String id = dictEmployeeEntityXtd.getId();
				BigDecimal calculateQYTD = calculateTDDL(month, id, "areaNo",dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
				String qyvalue = sysConfigService.getValue("singleColumn.qy", null);
				BigDecimal qyall = calculateQYTD.multiply(new BigDecimal(qyvalue));
				BigDecimal sumsingle = CalculateUtils.calculateQYZJJT(month, areaWorkNo,dataCalculateKService,dataContractXtdServiceXtd,hisEmployeeServiceXtd,dataMonthdirectServiceXtd, dataContractpayDetailServiceXtd, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataAreaachiRecordServiceXtd, sysConfigService,hisDepartmentServiceXtd);
				qyjjsum = qyjjsum.add(sumsingle).add(qyall);
			}
			String value = sysConfigService.getValue("areaAchievement.qyjjyc",null);
			BigDecimal coefficient = new BigDecimal(value);
			qyjjsum = qyjjsum.multiply(coefficient);
		}
		return qyjjsum;
	}
	/**
	 * 计算大区直接管理津贴
	 * @throws ParseException 
	 * 
	 */
	public static BigDecimal calculateDQZJ(String month,String employeeId,DataCalculateKService dataCalculateKService,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DictEmployeeService dictEmployeeService,DataBigareaachiRecordServiceXtd dataBigareaachiRecordServiceXtd,SysConfigService sysConfigService,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		BigDecimal sumDQZJ =new BigDecimal(0);
		BigDecimal addDQZJ =BigDecimal.ZERO;
		BigDecimal K1=new BigDecimal(1);
		BigDecimal K2=new BigDecimal(1);
		BigDecimal K3=new BigDecimal(1);
		BigDecimal K4=new BigDecimal(1);
		String deptNo=null;
		Map<String, Object> map=new HashMap<>();
		DictEmployeeEntity employee = dictEmployeeService.queryObject(employeeId);
		Date outorgtime = employee.getOutorgtime();
		String jobNo = employee.getJobNo();
		if("11.0".equals(jobNo)) {
			jobNo="11";
		}
		if("12.0".equals(jobNo)) {
			jobNo="12";
		}
		if("13.0".equals(jobNo)) {
			jobNo="13";
		}
		if("14.0".equals(jobNo)) {
			jobNo="14";
		}
		if("15.0".equals(jobNo)) {
			jobNo="15";
		}
		if("16.0".equals(jobNo)) {
			jobNo="16";
		}
		if("17.0".equals(jobNo)) {
			jobNo="17";
		}
		if("18.0".equals(jobNo)) {
			jobNo="18";
		}
		String name = employee.getName();
		String workno = employee.getWorkno();
		map.put("month", month);
		map.put("bigAreaNo", workno);
		//归属该大区的所有单子，包括租赁和买卖按签约年月计算的总和
		List<DirAllAchievement> achiListByContractMonth = dataContractpayDetailServiceXtd.getAchiListByContractMonth(map);
		Map<String, Object> deptmap=new HashMap<>();
		deptmap.put("workNo", workno);
		deptmap.put("deptNoFirst", "D");
		//此人的大区
		DictDepartmentEntityXtd dept = dictDepartmentServiceXtd.getDepNo(deptmap);
		if(dept==null) {
			//如果此人被降级，看看他是否在历史表里存在Q职级
			HisDepartmentEntityXtd hisDep = hisDepartmentServiceXtd.getDepNo(deptmap);
			if(hisDep==null) {
				//还找不到，说明不是被降级的
				return BigDecimal.ZERO;
			}
			deptNo=hisDep.getDeptNo();
		}else {
			deptNo = dept.getDeptNo();
		}


		//该员工的大区编号
		/*String deptNo = dept.getDeptNo();*/
		//当月此部门旗下所有员工
		List<DictEmployeeEntityXtd> allEmployee = getAllEmployee(month,deptNo, dictEmployeeServiceXtd, dictDepartmentServiceXtd,dataContractXtdServiceXtd);
		int size = allEmployee.size();
		List<DictDepartmentEntityXtd> fhByDeptNo = getFHByDeptNo(deptNo, dictDepartmentServiceXtd);
		//仅主管及主管以下都计算到了，而主管及以上没有。找到所有分行。
		size+=fhByDeptNo.size();
		result.clear();
		FHresult.clear();
		//遍历业绩，主要获取年月
		for (DirAllAchievement achi : achiListByContractMonth) {
			//签约年月
			String contractMonth = achi.getContractMonth();
			BigDecimal oneMonthAchi = achi.getOneMonthAchi();
			Map<String, Object> empmap=new HashMap<>();
			empmap.put("month", contractMonth);
			empmap.put("bigAreaNo", workno);
			//该部门该签单月目前为止开单人数，且已收不为0
			double actSize = 0;
			List<DataEmpAchi> activeEmpByMonth = dataContractpayDetailServiceXtd.getActiveEmpByMonth(empmap);
			for (DataEmpAchi dataEmpAchi : activeEmpByMonth) {
				String empId = dataEmpAchi.getEmployeeID();
				boolean judgeEmp = judgeEmp(contractMonth,empId,hisEmployeeServiceXtd,dictEmployeeServiceXtd,dataContractXtdServiceXtd);
				double judgeAct = judgeAct(contractMonth, empId, dataContractXtdServiceXtd);
				boolean judgeOutEmp = judgeOutEmp(contractMonth, empId,hisEmployeeServiceXtd, dictEmployeeServiceXtd);
				if(judgeEmp) {
					//判断合同月是否有主签约，前面已经对实收为0进行了筛选
					if(judgeOutEmp) {
						actSize=actSize+judgeAct;
					}

				}
			}	
			Map<String, Object> judmap=new HashMap<>();
			judmap.put("recordTime", contractMonth);
			judmap.put("calTime", month);
			judmap.put("bigAreaNo", workno);
			//查看非本月记录，有就是老记录，没有就是新记录
			List<DataBigareaachiRecordEntityXtd> listByCaltime = dataBigareaachiRecordServiceXtd.getListToCal(judmap);
			if(listByCaltime.size()==0) {
				//新记录
				//看新纪录有没有存
				Map<String, Object> newmap=new HashMap<>();
				newmap.put("recordTime", contractMonth);
				newmap.put("calTime", month);
				newmap.put("bigAreaNo", workno);
				List<DataBigareaachiRecordEntityXtd> thisMonthRecord = dataBigareaachiRecordServiceXtd.getListByCaltime(newmap);
				if(thisMonthRecord.size()==0) {
					//新纪录没有存，计算之后存储
					//人均业绩
					if(size!=0) {
						//先算K1
						if("15".equals(jobNo)) {
							String value = sysConfigService.getValue("ddqtt", null);
							K1=new BigDecimal(value);
						}else if(!("17".equals(jobNo)||"18".equals(jobNo))) {
							//不是高级和资深都是普通
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "dqyjqj", 1);
						}else if("17".equals(jobNo)) {
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "dqyjqj", 2);
						}else if("18".equals(jobNo)) {
							K1=choseCoefficient(sysConfigService, oneMonthAchi, "dqyjqj", 3);
						}
						BigDecimal divide = oneMonthAchi.divide(new BigDecimal(size),4, BigDecimal.ROUND_HALF_UP);
						K2=getCoefficient(sysConfigService, divide, "dqrj");
						BigDecimal act = new BigDecimal(actSize).divide(new BigDecimal(size),4, BigDecimal.ROUND_HALF_UP);
						K3=getCoefficient(sysConfigService, act, "dqhdl");
					}else {
						K2=new BigDecimal(0);
						K3=new BigDecimal(0);
					}					
					//活动率					
					String value = sysConfigService.getValue("groupAchievement.dqzjyc", null);
					K4=new BigDecimal(value);
					DataCalculateKEntity k=new DataCalculateKEntity();
					k.setCaltime(month);
					k.setRecordtime(contractMonth);
					k.setDeptno("D");
					k.setJobno(jobNo);
					k.setWorkno(workno);
					k.setName(name);
					k.setK1(K1);
					k.setK2(K2);
					k.setK3(K3);
					k.setK4(K4);
					dataCalculateKService.save(k);
					BigDecimal thisMonthZJ = K1.multiply(K2).multiply(K3).multiply(K4).multiply(oneMonthAchi);
					sumDQZJ=sumDQZJ.add(thisMonthZJ);
					//计算完毕开始存储
					DataBigareaachiRecordEntityXtd bigAreaRecord=new DataBigareaachiRecordEntityXtd();
					bigAreaRecord.setBigareano(workno);
					bigAreaRecord.setCaltime(month);
					bigAreaRecord.setPeoplecount(new BigDecimal(size));
					bigAreaRecord.setRecordtime(contractMonth);
					bigAreaRecord.setTotalachievement(oneMonthAchi);
					bigAreaRecord.setTotaldirect(thisMonthZJ);
					dataBigareaachiRecordServiceXtd.save(bigAreaRecord);
					//保存当月收取的间接管理津贴
					DataMonthdirectEntityXtd monthdir=new DataMonthdirectEntityXtd();
					monthdir.setWorkno(workno);
					monthdir.setAreano(deptNo);
					monthdir.setCalmonth(month);
					monthdir.setBasicmonth(contractMonth);
					monthdir.setDirectmoney(thisMonthZJ);
					dataMonthdirectServiceXtd.save(monthdir);

				}else {
					//新纪录已存
					Map<String, Object> mapp=new HashMap<>();
					mapp.put("recordTime", contractMonth);
					mapp.put("bigAreaNo", workno);
					List<DataBigareaachiRecordEntityXtd> listByrecordTime = dataBigareaachiRecordServiceXtd.getListByrecordTime(mapp);
					BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
					sumDQZJ=sumDQZJ.add(totaldirect);
				}
			}else {
				//已有记录			
				//虽然有非本月的记录，还要判断本月有没有记录这个
				Map<String, Object> newmap=new HashMap<>();
				newmap.put("recordTime", contractMonth);
				newmap.put("calTime", month);
				newmap.put("bigAreaNo", workno);
				List<DataBigareaachiRecordEntityXtd> thisMonthRecord = dataBigareaachiRecordServiceXtd.getListByCaltime(newmap);
				if(thisMonthRecord.size()==0) {
					//没有存，计算之后存储
					//人均业绩
					Map<String, Object> empmap1=new HashMap<>();
					empmap1.put("recordTime", contractMonth);
					empmap1.put("bigAreaNo", workno);
					List<DataBigareaachiRecordEntityXtd> listByrecordTime = dataBigareaachiRecordServiceXtd.getListByrecordTime(empmap1);
					DataBigareaachiRecordEntityXtd dataBigareaachiRecordEntityXtd = listByrecordTime.get(0);
					//总人不变
					BigDecimal peoplecount = dataBigareaachiRecordEntityXtd.getPeoplecount();
					BigDecimal totaldirect = dataBigareaachiRecordEntityXtd.getTotaldirect();
					BigDecimal totalachievement = dataBigareaachiRecordEntityXtd.getTotalachievement();
					totalachievement=totalachievement.add(oneMonthAchi);
					
					//这里的职级可能发生变化，要回溯到当月职级
					Map<String, Object> empmap2=new HashMap<>();
					empmap2.put("workNo", workno);
					empmap2.put("hisyear", contractMonth.substring(0, 4));
					empmap2.put("hismonth", contractMonth.substring(4, 6));
					HisEmployeeEntityXtd queryEmployeeByInOrgTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(empmap2);
					String jobNo2 = queryEmployeeByInOrgTime.getJobno();
					if("11.0".equals(jobNo2)) {
						jobNo2="11";
					}
					if("12.0".equals(jobNo2)) {
						jobNo2="12";
					}
					if("13.0".equals(jobNo2)) {
						jobNo2="13";
					}
					if("14.0".equals(jobNo2)) {
						jobNo2="14";
					}
					if("15.0".equals(jobNo2)) {
						jobNo2="15";
					}
					if("16.0".equals(jobNo2)) {
						jobNo2="16";
					}
					if("17.0".equals(jobNo2)) {
						jobNo2="17";
					}
					if("18.0".equals(jobNo2)) {
						jobNo2="18";
					}

					
					
					

					//先算K1
					if("15".equals(jobNo2)) {
						String value = sysConfigService.getValue("ddqtt", null);
						K1=new BigDecimal(value);
					}else if(!("17".equals(jobNo2)||"18".equals(jobNo2))) {
						//不是高级和资深都是普通
						K1=choseCoefficient(sysConfigService, totalachievement, "dqyjqj", 1);
					}else if("17".equals(jobNo2)) {
						K1=choseCoefficient(sysConfigService, totalachievement, "dqyjqj", 2);
					}else if("18".equals(jobNo2)) {
						K1=choseCoefficient(sysConfigService, totalachievement, "dqyjqj", 3);
					}
					BigDecimal divide = totalachievement.divide(peoplecount,4, BigDecimal.ROUND_HALF_UP);
					K2=getCoefficient(sysConfigService, divide, "dqrj");
					//活动率
					BigDecimal act = new BigDecimal(actSize).divide(peoplecount,4, BigDecimal.ROUND_HALF_UP);
					K3=getCoefficient(sysConfigService, act, "fhhdl");
					String value = sysConfigService.getValue("groupAchievement.dqzjyc", null);
					K4=new BigDecimal(value);
					DataCalculateKEntity k=new DataCalculateKEntity();
					k.setCaltime(month);
					k.setRecordtime(contractMonth);
					k.setDeptno("D");
					k.setJobno(jobNo2);
					k.setWorkno(workno);
					k.setName(name);
					k.setK1(K1);
					k.setK2(K2);
					k.setK3(K3);
					k.setK4(K4);
					dataCalculateKService.save(k);
					BigDecimal thisMonthZJ = K1.multiply(K2).multiply(K3).multiply(K4).multiply(totalachievement);
					BigDecimal thisMonthGet=thisMonthZJ.subtract(totaldirect);
					addDQZJ=addDQZJ.add(thisMonthGet);
					//计算完毕开始存储
					DataBigareaachiRecordEntityXtd bigAreaRecord=new DataBigareaachiRecordEntityXtd();
					bigAreaRecord.setBigareano(workno);
					bigAreaRecord.setCaltime(month);
					bigAreaRecord.setPeoplecount(peoplecount);
					bigAreaRecord.setRecordtime(contractMonth);
					bigAreaRecord.setTotalachievement(totalachievement);
					bigAreaRecord.setTotaldirect(thisMonthZJ);
					dataBigareaachiRecordServiceXtd.save(bigAreaRecord);
					DataMonthdirectEntityXtd monthdir=new DataMonthdirectEntityXtd();
					monthdir.setWorkno(workno);
					monthdir.setAreano(deptNo);
					monthdir.setCalmonth(month);
					monthdir.setBasicmonth(contractMonth);
					monthdir.setDirectmoney(thisMonthGet);
					dataMonthdirectServiceXtd.save(monthdir);
				}else {
					//纪录已存.获取新月直接减去旧月
					Map<String, Object> empmap1=new HashMap<>();
					empmap1.put("recordTime", contractMonth);
					empmap1.put("bigAreaNo", workno);
					List<DataBigareaachiRecordEntityXtd> listByrecordTime = dataBigareaachiRecordServiceXtd.getListByrecordTime(empmap1);
					if(listByrecordTime.size()>1) {
						BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
						BigDecimal totaldirectold = listByrecordTime.get(1).getTotaldirect();
						BigDecimal subtract = totaldirect.subtract(totaldirectold);
						addDQZJ=addDQZJ.add(subtract);
					}else {
						BigDecimal totaldirect = listByrecordTime.get(0).getTotaldirect();
						addDQZJ=addDQZJ.add(totaldirect);
					}

				}

			}
		}

		if(outorgtime!=null) {
			System.out.println(addDQZJ);
			addDQZJ=BigDecimal.ZERO;
			
		}
		sumDQZJ=sumDQZJ.add(addDQZJ);


		return sumDQZJ;

	}
	/**
	 * 大区间接管理津贴
	 * @throws ParseException 
	 */
	public static BigDecimal calculateDQJJ(String month,String employeeId,DataCalculateKService dataCalculateKService,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DictEmployeeService dictEmployeeService,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataBigareaachiRecordServiceXtd dataBigareaachiRecordServiceXtd,SysConfigService sysConfigService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,HisDepartmentServiceXtd hisDepartmentServiceXtd) throws ParseException {
		BigDecimal DQJJsum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeServiceXtd.queryObject(employeeId);
		String workno = employee.getWorkno();
		Map<String, Object> map =new HashMap<>();
		map.put("bigAreaBredNo", workno);
		List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(map);
		if(queryBredNo.size()!=0) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryBredNo) {
				String bredworkNo = dictEmployeeEntityXtd.getWorkno();


				Map<String, Object> deptmap=new HashMap<>();
				deptmap.put("workNo", bredworkNo);
				deptmap.put("deptNoFirst", "D");
				//此人的大区
				DictDepartmentEntityXtd dept = dictDepartmentServiceXtd.getDepNo(deptmap);
				//不为空说明此人有管辖的大区
				if(dept!=null) {
					String id = dictEmployeeEntityXtd.getId();
					BigDecimal calculateDQTD = calculateTDDL(month, id, "bigAreaNo", dictEmployeeServiceXtd, dataContractpayDetailServiceXtd);
					String dqvalue = sysConfigService.getValue("singleColumn.dq", null);
					BigDecimal dqall = calculateDQTD.multiply(new BigDecimal(dqvalue));
					BigDecimal calculateDQZJ = calculateDQZJ(month, id,dataCalculateKService,hisEmployeeServiceXtd,dataContractXtdServiceXtd,dataMonthdirectServiceXtd,dictEmployeeService, dataBigareaachiRecordServiceXtd, sysConfigService, dictDepartmentServiceXtd, dictEmployeeServiceXtd, dataContractpayDetailServiceXtd,hisDepartmentServiceXtd);
					DQJJsum=DQJJsum.add(calculateDQZJ).add(dqall);
				}
			}
		}

		//间接提成系数
		String value = sysConfigService.getValue("groupAchievement.dqjjyc", null);
		DQJJsum=DQJJsum.multiply(new BigDecimal(value));
		return DQJJsum;

	}
	/**
	 * 单列计算(团队)
	 */
	public static BigDecimal calculateTDDL(String month,String employeeId,String deptName,DictEmployeeService dictEmployeeService,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd) {
		BigDecimal TDDLsum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeService.queryObject(employeeId);
		String workno = employee.getWorkno();
		Map<String, Object> map=new HashMap<>();
		map.put("month", month);
		map.put(deptName, workno);
		List<DirAllAchievement> zlContractListByEmpId = dataContractpayDetailServiceXtd.getZLList(map);
		for (DirAllAchievement dirAllAchievement : zlContractListByEmpId) {
			TDDLsum=TDDLsum.add(dirAllAchievement.getOneMonthAchi());
		}
		return TDDLsum;
	}

	/**
	 * 单列育成
	 */
	/*	public static BigDecimal calculateDLYC(String month,String employeeId,String deptName,String bredNo,String firstWord,DictEmployeeService dictEmployeeService,DictDepartmentServiceXtd dictDepartmentServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd) {
		BigDecimal DLYCsum=new BigDecimal(0);
		DictEmployeeEntity employee = dictEmployeeService.queryObject(employeeId);
		String workno = employee.getWorkno();
		Map<String, Object> map =new HashMap<>();
		map.put(bredNo, workno);
		List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(map);
		for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryBredNo) {
			String bredworkNo = dictEmployeeEntityXtd.getWorkno();
			Map<String, Object> deptmap=new HashMap<>();
			deptmap.put("workNo", bredworkNo);
			deptmap.put("deptNoFirst", firstWord);
			//此人的团队
			DictDepartmentEntityXtd dept = dictDepartmentServiceXtd.getDepNo(deptmap);
			//不为空说明此人有管辖的团队
			if(dept!=null) {
				String id = dictEmployeeEntityXtd.getId();
				BigDecimal calculateFDZJ = calculateTDDL(month, id,deptName,dictEmployeeService, dataContractpayDetailServiceXtd);
				DLYCsum=DLYCsum.add(calculateFDZJ);
			}
		}

		return DLYCsum;

	}*/
	/**
	 * 输入时间和员工id,看是否是15号之前的新员工
	 */
	public static boolean judgeEmp(String month,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd) {
		//如果该员工离职了，还要去历史表查
		Date inorgtime=null;
		Date outorgtime=null;
		String jobNo=null;
		DictEmployeeEntity employeeEntity = dictEmployeeServiceXtd.queryObject(employeeId);
		if("34ce390bc5134125b86028f64032d286".equals(employeeId)) {
			System.out.println();
		}
		if(month.contains("-")) {
			month=month.replace("-","");
		}
		if(employeeEntity!=null) {
			inorgtime = employeeEntity.getInorgtime();
			jobNo = employeeEntity.getJobNo();
			if("11.0".equals(jobNo)) {
				jobNo="11";
			}
			if("12.0".equals(jobNo)) {
				jobNo="12";
			}
			if("13.0".equals(jobNo)) {
				jobNo="13";
			}
			if("14.0".equals(jobNo)) {
				jobNo="14";
			}
			if("15.0".equals(jobNo)) {
				jobNo="15";
			}
			if("16.0".equals(jobNo)) {
				jobNo="16";
			}
			if("17.0".equals(jobNo)) {
				jobNo="17";
			}
			if("18.0".equals(jobNo)) {
				jobNo="18";
			}

		}else {

			List<HisEmployeeEntityXtd> hisList = hisEmployeeServiceXtd.queryEmployeeByHisId(employeeId);
			if(hisList!=null&&hisList.size()!=0) {
				inorgtime = hisList.get(0).getInorgtime();
				outorgtime = hisList.get(0).getOutorgtime();
				jobNo=hisList.get(0).getJobno();
				if("11.0".equals(jobNo)) {
					jobNo="11";
				}
				if("12.0".equals(jobNo)) {
					jobNo="12";
				}
				if("13.0".equals(jobNo)) {
					jobNo="13";
				}
				if("14.0".equals(jobNo)) {
					jobNo="14";
				}
				if("15.0".equals(jobNo)) {
					jobNo="15";
				}
				if("16.0".equals(jobNo)) {
					jobNo="16";
				}
				if("17.0".equals(jobNo)) {
					jobNo="17";
				}
				if("18.0".equals(jobNo)) {
					jobNo="18";
				}
			}
		}
		Map<String,Object> map=new HashMap<>();
		map.put("employeeID",employeeId );
		map.put("month", month);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM-dd");
		String format = sdf.format(inorgtime);

		String substring = format.substring(0, 6);

		if(month.equals(substring)&&("00".equals(jobNo)||"01".equals(jobNo)||"02".equals(jobNo)||"04".equals(jobNo)||"071".equals(jobNo))) {
			String substring2 = format.substring(7, 9);
			if(Integer.valueOf(substring2)<=15) {	
				//本月15号之前入职，不存在1-5日内入职又离职的情况
				return true;
			}
		}else{
			//如果是之前月份也算人力
			if(Integer.parseInt(month)>Integer.parseInt(substring)) {
				if(outorgtime==null) {
					return true;
				}else {
					//之前入职的员工判断离职,若离职，要判断是否是本月1-5日离职的
					String format2 = sdf.format(outorgtime);
					String substringout = format2.substring(0, 6);
					String substringout2 = format2.substring(7, 9);
					if(Integer.valueOf(substringout2)>=6) {	
						//6号以后离职的都算人力
						return true;
					}else {
						if(month.equals(substringout)) {
							//本月1-5日离职的看本月应收算人力
							BigDecimal queryAssessmentCountShould = dataContractXtdServiceXtd.queryAssessmentCountShould(map);
							if(queryAssessmentCountShould==null) {
								queryAssessmentCountShould=BigDecimal.ZERO;
							}
							if(queryAssessmentCountShould.compareTo(BigDecimal.ZERO)==1) {
								return true;
							}else {
								return false;
							}
						}else {
							return true;
						}
					}
				}
			}else {
				//当月15号以后入职的，要根据单月预收算人力
				BigDecimal queryAssessmentCountShould = dataContractXtdServiceXtd.queryAssessmentCountShould(map);
				if(queryAssessmentCountShould==null) {
					queryAssessmentCountShould=BigDecimal.ZERO;
				}
				if(queryAssessmentCountShould.compareTo(BigDecimal.ZERO)==1) {
					return true;
				}else {
					return false;
				}

			}		
		}
		return false;


	}
	/**
	 * 计算正式置业顾问的新人卓越奖
	 */
	public static  BigDecimal calculateXRZYJ(String month,String employeeId,String workNo,String jobno,DictEmployeeEntityXtd employee,DataPayrollServiceXtd dataPayrollServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd,SysConfigService sysConfigService) {
		BigDecimal sum = new BigDecimal(0);
		BigDecimal sumAchi = new BigDecimal(0);
		BigDecimal sumCount = new BigDecimal(0);
		String monthnew = month.replace("-", "");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		//入职时间
		Date inOrgTime = employee.getInorgtime();
		String inOrgTimeString = sdf.format(inOrgTime);
		//入职的年月
		String inOrgTimeNew = inOrgTimeString.substring(0, 7).replace("-", "");
		Integer inOrgTimeInt = Integer.valueOf(inOrgTimeNew);
		Integer inOrgTimeInt2 = Integer.valueOf(inOrgTimeNew);
		//入职的月份
		String inTimeNew2= inOrgTimeNew.substring(4, 6);
		Integer inTimeInt2 = Integer.valueOf(inTimeNew2);
		//入职的年份
		String inTimeNew3 = inOrgTimeString.substring(0, 4);
		Integer inTimeInt3 = Integer.valueOf(inTimeNew3);
		Map<String, Object> map3 = new HashMap<>();
		map3.put("workNo", workNo);
		map3.put("hismonth", inTimeInt2);
		map3.put("hisyear", inTimeInt3);
		HisEmployeeEntityXtd employeeInTime = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map3);
		if(employeeInTime==null) {
			return sum;
		}
		//转正时间
		Date zzTime = employee.getZztime();	
		String zzTimeString = sdf.format(zzTime);	
		//转正年月
		String zzTimeNew = zzTimeString.replace("-", "").substring(0, 6);
		Integer zzTimeInt = Integer.parseInt(zzTimeNew);
		//转正的月份
		String zzTimeNew2 = zzTimeString.replace("-", "").substring(4, 6);	
		Integer zzTimeInt2 = Integer.parseInt(zzTimeNew2);
		//转正的后一个月
		Integer zzTimeNext = 0;
		if(zzTimeInt2==12) {
			zzTimeNext = zzTimeInt+100-11;
		}else {
			zzTimeNext = zzTimeInt+1;
		}
		//转正的前一个月
		Integer zzTimeBeforeInt = 0;
		if(zzTimeInt2==01) {
			zzTimeBeforeInt = zzTimeInt-89;
		}else {
			zzTimeBeforeInt = zzTimeInt-1;
		}
		String zzTimeBefore = zzTimeBeforeInt.toString().substring(0, 4)+"-"+zzTimeBeforeInt.toString().substring(4, 6);
		//当月是转正后的次月，判断是否发放新人卓越奖
		if(zzTimeNext.toString().equals(monthnew)) {
			//判断是上半月还是下半月
			String jobnoOld = employeeInTime.getJobno();
			String inOrgTimeNew2 = inOrgTimeString.substring(8, 10);
			int monthcount = 0;
			if(Integer.valueOf(inOrgTimeNew2)<=15) {
				//上半月入职,计算前3个月的业绩
				monthcount = 3;			
			}else {
				//下半月入职,计算前4个月的业绩（包括当月）
				monthcount = 4;
			}
			int i = 0;
			int j = 0;
			int m = 0;
			BigDecimal firstofmonth = new BigDecimal(0);
			String monthpayrollrecord = "";
			//试用置业顾问考核期的累计应收和合同个数
			while(i<monthcount&&inOrgTimeInt<zzTimeInt) {
				String monthpayroll = inOrgTimeInt.toString().substring(0, 4)+"-"+inOrgTimeInt.toString().substring(4, 6);
				Integer inOrgTimeIntmonth = Integer.valueOf(inOrgTimeInt.toString().substring(4, 6));
				String monthpayroll2 = monthpayroll.replace("-", "");
				Map<String, Object> map2 =new HashMap<>();
				map2.put("employeeId", employeeId);
				map2.put("month", monthpayroll2);
				sumAchi = sumAchi.add(dataContractXtdServiceXtd.queryAssessmentAchi(map2));
				sumCount = sumCount.add(dataContractXtdServiceXtd.queryAssessmentCount(map2));
				i++;

				if(inOrgTimeIntmonth==12) {
					inOrgTimeInt = inOrgTimeInt+89;
				}else {
					inOrgTimeInt++;
				}
			}
			//考核期内业绩大于等于20000，合同个数大于等于2个,计算需要返还的金额
			if((!(sumAchi.compareTo(new BigDecimal(20000))==-1))&&(!(sumCount.compareTo(new BigDecimal(2))==-1))) {
				while(inOrgTimeInt2<zzTimeInt) {
					String monthpayroll = inOrgTimeInt2.toString().substring(0, 4)+"-"+inOrgTimeInt2.toString().substring(4, 6);
					Integer inOrgTimeIntmonth = Integer.valueOf(inOrgTimeInt2.toString().substring(4, 6));
					String monthpayroll2 = monthpayroll.replace("-", "");
					Map<String, Object> map =new HashMap<>();
					map.put("employeeId", employeeId);
					map.put("payrollMonth", monthpayroll);
					//得到计算月的工资详情
					DataPayrollEntityXtd dataPayrollEntityXtd = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(map);
					//计算月当月新开单的记录情况
					Map<String, Object> hismap =new HashMap<>();
					hismap.put("month", monthpayroll2);
					hismap.put("employeeId", employeeId);
					hismap.put("calTime", monthpayroll);
					DataEmployeeachiRecordEntityXtd hisrecord = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap);
					//转正前一个月的累计记录情况
					Map<String, Object> hismap2 =new HashMap<>();
					hismap2.put("month", monthpayroll2);
					hismap2.put("employeeId", employeeId);
					hismap2.put("calTime", zzTimeBefore);
					DataEmployeeachiRecordEntityXtd hisrecord2 = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap2);
					//未开端口的计算方法
					if("01".equals(jobnoOld)) {
						//计算月新开单的业绩的底薪大于1500的计算方法
						BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, hisrecord.getTotalachievement(),"dxqj");
						if(coefficient.compareTo(new BigDecimal(1500))==1) {
							sum = sum.add(hisrecord2.getTotalincome().add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
						}else if(inOrgTimeInt2==Integer.valueOf(inOrgTimeNew)){
							//入职首月新开单的业绩的底薪小于等于1500的计算方法
							//入职的次月
							Integer inOrgTimeInt2Next;
							if(inOrgTimeIntmonth==12) {
								inOrgTimeInt2Next = inOrgTimeInt2+89;
							}else {
								inOrgTimeInt2Next = inOrgTimeInt2+1;
							}
							String monthpayroll3 = inOrgTimeInt2Next.toString().substring(0, 4)+"-"+inOrgTimeInt2Next.toString().substring(4, 6);
							Map<String, Object> hismap3 =new HashMap<>();
							hismap3.put("month", monthpayroll2);
							hismap3.put("employeeId", employeeId);
							hismap3.put("calTime", monthpayroll3);
							//入职次月的业绩、底薪详细记录
							DataEmployeeachiRecordEntityXtd hisrecord3 = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap3);
							if(!(hisrecord3.getTotalincome().compareTo(new BigDecimal(1500))==1)) {
								//入职次月的底薪小于等于1500，则不纳入计算
								sum = sum.add(hisrecord2.getTotalincome().subtract(hisrecord3.getTotalincome()).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
							}else {
								//入职次月的底薪大于1500，则纳入计算
								sum = sum.add(hisrecord2.getTotalincome().subtract(dataPayrollEntityXtd.getFirstmonthwage()).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
							}									
						}else {
							//非入职首月新开单的业绩的底薪小于等于1500的计算方法
							sum = sum.add(hisrecord2.getTotalincome().subtract(hisrecord.getTotalincome()).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
						}
					}else if("00".equals(jobnoOld)){
						//已开端口的计算方法
						if(firstofmonth.compareTo(new BigDecimal(3900))==-1) {
							//首月底薪3900先算完
							firstofmonth = firstofmonth.add(dataPayrollEntityXtd.getFirstmonthwage());
							monthpayrollrecord = monthpayroll;
							m++;
						}else {
							//首月底薪算完了，计算月底薪大于1500的算法
							if(hisrecord.getTotalincome().compareTo(new BigDecimal(1500))==1) {
								sum = sum.add(hisrecord2.getTotalincome().add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
							}else {
								//计算月底薪小于等于1500的算法
								sum = sum.add(hisrecord2.getTotalincome().subtract(hisrecord.getTotalincome()).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
							}
						}
					}
					if(inOrgTimeIntmonth==12) {
						inOrgTimeInt2 = inOrgTimeInt2+89;
					}else {
						inOrgTimeInt2++;
					}
					j++;
				}
				//循环计算中漏掉的一个月
				if(firstofmonth.compareTo(new BigDecimal(3900))==1) {
					String monthpayrollrecordnew = monthpayrollrecord.replace("-", "");
					//计算月当月新开单的记录情况
					Map<String, Object> hismap =new HashMap<>();
					hismap.put("month", monthpayrollrecordnew);
					hismap.put("employeeId", employeeId);
					hismap.put("calTime", monthpayrollrecord);
					DataEmployeeachiRecordEntityXtd hisrecord = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap);
					//转正前一个月的累计记录情况
					Map<String, Object> hismap2 =new HashMap<>();
					hismap2.put("month", monthpayrollrecordnew);
					hismap2.put("employeeId", employeeId);
					hismap2.put("calTime", zzTimeBefore);
					DataEmployeeachiRecordEntityXtd hisrecord2 = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap2);
					//当月新开单的实收业绩
					BigDecimal coefficient = CalculateUtils.getCoefficient(sysConfigService, hisrecord.getTotalachievement(),"dxqj");
					if(m==3&&j==3) {
						if(coefficient.compareTo(new BigDecimal(1500))==1) {
							sum = sum.add(firstofmonth.subtract(new BigDecimal(3900)).divide(new BigDecimal(4),4, BigDecimal.ROUND_HALF_UP));
						}
					}else if(coefficient.compareTo(new BigDecimal(1500))==1) {
						//首月底薪算完了，计算月底薪大于1500的算法
						sum = sum.add(hisrecord2.getTotalincome().add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
					}else {
						//计算月底薪小于等于1500的算法，分次月底薪大于1500和次月底薪小于等于1500两种情况
						Integer monthpayrollrecordMonth = Integer.valueOf(monthpayrollrecordnew.toString().substring(4, 6));
						//计算月的次月
						Integer monthpayrollrecordNext;
						if(monthpayrollrecordMonth==12) {
							monthpayrollrecordNext = Integer.valueOf(monthpayrollrecordnew)+89;
						}else {
							monthpayrollrecordNext = Integer.valueOf(monthpayrollrecordnew)+1;
						}
						String monthpayrollrecordString = monthpayrollrecordNext.toString().substring(0, 4)+"-"+monthpayrollrecordNext.toString().substring(4, 6);
						Map<String, Object> hismap3 =new HashMap<>();
						hismap3.put("month", monthpayrollrecordnew);
						hismap3.put("employeeId", employeeId);
						hismap3.put("calTime", monthpayrollrecordString);
						//计算月次月的业绩、底薪详细记录
						DataEmployeeachiRecordEntityXtd hisrecord3 = dataEmployeeachiRecordServiceXtd.queryObjectByMonthAndCaltime(hismap3);
						if(!(hisrecord3.getTotalincome().compareTo(new BigDecimal(1500))==1)) {
							//计算月次月的底薪小于等于1500，次月则不纳入新人卓越奖计算
							sum = sum.add(hisrecord2.getTotalincome().subtract(hisrecord3.getTotalincome()).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
						}else {
							//计算月次月的底薪大于1500，次月则纳入新人卓越奖计算，计算月不纳入新人卓越奖计算
							sum = sum.add(hisrecord2.getTotalincome().subtract(firstofmonth.subtract(new BigDecimal(3900))).add(hisrecord2.getTotalextract()).multiply(new BigDecimal(0.2)));
						}
					}
				}
			}	
		}
		return sum;
	}

	//跟据转正日期获得要计算的月份
	public static List<String> getZZCheckTime(String month){
		List<String> list =new ArrayList<>();
		String a = month.substring(5, 7);
		String b = month.substring(0, 5);
		if("01".equals(a)) {
			list.add(b+"03");
			list.add(b+"02");
			list.add(b+"01");
		}else if("02".equals(a)) {
			list.add(b+"03");
			list.add(b+"02");
		}else if("03".equals(a)) {
			list.add(b+"06");
			list.add(b+"05");
			list.add(b+"04");
			list.add(b+"03");
		}else if("04".equals(a)) {
			list.add(b+"06");
			list.add(b+"05");
			list.add(b+"04");
		}else if("05".equals(a)) {
			list.add(b+"06");
			list.add(b+"05");
		}else if("06".equals(a)) {
			list.add(b+"09");
			list.add(b+"08");
			list.add(b+"07");
			list.add(b+"06");
		}else if("07".equals(a)) {
			list.add(b+"09");
			list.add(b+"08");
			list.add(b+"07");
		}else if("08".equals(a)) {
			list.add(b+"09");
			list.add(b+"08");
		}else if("09".equals(a)) {
			list.add(b+"12");
			list.add(b+"11");
			list.add(b+"10");
			list.add(b+"09");
		}else if("10".equals(a)) {
			list.add(b+"12");
			list.add(b+"11");
			list.add(b+"10");
		}else if("11".equals(a)) {
			list.add(b+"12");
			list.add(b+"11");
		}else if("12".equals(a)) {
			list.add(Integer.parseInt(b.replace("-", ""))+1+"-03");
			list.add(Integer.parseInt(b.replace("-", ""))+1+"-02");
			list.add(Integer.parseInt(b.replace("-", ""))+1+"-01");
			list.add(b+"12");     	
		}
		return list;	
	}
	//根据计算日期获得计算月份
	public static List<String> getCheckTime(String month){
		List<String> list =new ArrayList<>();
		String a = month.substring(5, 7);
		String b = month.substring(0, 5);
		if("01".equals(a)) {
			list.add(b+"01");
		}else if("02".equals(a)) {
			list.add(b+"02");
			list.add(b+"01");
		}else if("03".equals(a)) {
			list.add(b+"03");
			list.add(b+"02");
			list.add(b+"01");
		}else if("04".equals(a)) {
			list.add(b+"04");
		}else if("05".equals(a)) {      	
			list.add(b+"05");
			list.add(b+"04");
		}else if("06".equals(a)) {
			list.add(b+"06");
			list.add(b+"05");
			list.add(b+"04");
		}else if("07".equals(a)) {
			list.add(b+"07");
		}else if("08".equals(a)) {
			list.add(b+"08");
			list.add(b+"07");
		}else if("09".equals(a)) {
			list.add(b+"09");
			list.add(b+"08");
			list.add(b+"07");
		}else if("10".equals(a)) {
			list.add(b+"10");
		}else if("11".equals(a)) {
			list.add(b+"11");
			list.add(b+"10");
		}else if("12".equals(a)) {
			list.add(b+"12");
			list.add(b+"11");
			list.add(b+"10");        	
		}
		return list;	
	}
	//计算和保存所有正式员工和主管的个人业绩考核信息
	public static void saveformalInfo(String month,DataFormalcheckServiceXtd dataFormalcheckServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd) {

		//获取正式和主管的人
		List<DictEmployeeEntityXtd> listByJobNo = dictEmployeeServiceXtd.getListByJobNo("02");
		List<DictEmployeeEntityXtd> listByJobNo1 = dictEmployeeServiceXtd.getListByJobNo("04");
		List<DictEmployeeEntityXtd> listByJobNo2 = dictEmployeeServiceXtd.getListByJobNo("05");
		List<DictEmployeeEntityXtd> listByJobNo3 = dictEmployeeServiceXtd.getListByJobNo("06");
		listByJobNo.addAll(listByJobNo3);
		listByJobNo.addAll(listByJobNo2);
		listByJobNo.addAll(listByJobNo1);
		//每个员工细化，计算填充存储
		for (DictEmployeeEntityXtd dictEmployeeEntityXtd : listByJobNo) {
			BigDecimal sumMoney=new BigDecimal(0);
			BigDecimal shouldMoney=new BigDecimal(0);
			BigDecimal checkMonth=new BigDecimal(0);
			DataFormalcheckEntityXtd formalcheck=new DataFormalcheckEntityXtd();
			String employeeId = dictEmployeeEntityXtd.getId();
			Date zztime = dictEmployeeEntityXtd.getZztime();
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM");
			String format = sdf.format(zztime);
			List<String> zzCheckTime = CalculateUtils.getZZCheckTime(format);
			//对应近期转正的员工根据转正时间获取最大特例时间
			String calMonth = zzCheckTime.get(0);
			if(Integer.parseInt(calMonth.replace("-", ""))>=Integer.parseInt(month.replace("-", ""))) {
				//在时间范围内，不需要新的时间范围
				List<String> checkTime = CalculateUtils.getZZCheckTime(format);
				for (String tmonth : checkTime) {
					//这里要判断考核期月份是否已经到来
					if(Integer.parseInt(tmonth.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
						//小于算一个月
						checkMonth=checkMonth.add(new BigDecimal(1));
						Map<String, Object> map=new HashMap<>();
						map.put("month",tmonth.replace("-", "") );
						map.put("employeeID", employeeId);
						EmpOneMonthAchi monthInfo = dataContractpayDetailServiceXtd.getMonthInfo(map);
						//这里是累计实收
						if(monthInfo!=null) {				
							sumMoney=sumMoney.add(monthInfo.getSumMonthMoney());
						}
						EmpMonthShouldAchi shouldInfo = dataFormalcheckServiceXtd.getShouldByMonth(map);
						//这里是累计应收
						if(shouldInfo!=null) {				
							shouldMoney=shouldMoney.add(shouldInfo.getShouldMoney());
						}
					}
				}
				//计算近三个月的实收
				String contractmonth=month.replace("-", "");
				int thisMonth = Integer.parseInt(contractmonth);
				int lastMonth=0;
				int lastlastMonth=0;
				//如果是一月份，则算到去年12月份
				if((thisMonth-1)%100==0) {
					lastMonth=thisMonth-100+11;
				}else {
					lastMonth=thisMonth-1;
				}
				if((thisMonth-2)%100==0) {
					lastlastMonth=thisMonth-100+10;
				}else {
					lastlastMonth=thisMonth-1;
				}
				Map<String, Object> mapp = new HashMap<>();
				mapp.put("month", String.valueOf(thisMonth));
				mapp.put("employeeID", employeeId);
				BigDecimal allAchi = dataContractpayDetailServiceXtd.getAllAchi(mapp);
				if(allAchi==null) {
					allAchi=new BigDecimal(0);
				}
				Map<String, Object> mapp2 = new HashMap<>();
				mapp2.put("month", String.valueOf(lastMonth));
				mapp2.put("employeeID", employeeId);
				BigDecimal allAchi2 = dataContractpayDetailServiceXtd.getAllAchi(mapp2);
				if(allAchi2==null) {
					allAchi2=new BigDecimal(0);
				}
				Map<String, Object> mapp3 = new HashMap<>();
				mapp3.put("month", String.valueOf(lastlastMonth));
				mapp3.put("employeeID", employeeId);
				BigDecimal allAchi3 = dataContractpayDetailServiceXtd.getAllAchi(mapp3);
				if(allAchi3==null) {
					allAchi3=new BigDecimal(0);
				}
				BigDecimal allachi=allAchi.add(allAchi2).add(allAchi3);
				BigDecimal contractCount = dataFormalcheckServiceXtd.getContractCount(mapp);
				if(contractCount==null) {
					contractCount=new BigDecimal(0);
				}
				BigDecimal contractCount2 = dataFormalcheckServiceXtd.getContractCount(mapp2);
				if(contractCount2==null) {
					contractCount2=new BigDecimal(0);
				}
				BigDecimal contractAchi = dataFormalcheckServiceXtd.getContractAchi(mapp);
				if(contractAchi==null) {
					contractAchi=new BigDecimal(0);
				}
				BigDecimal contractAchi2 = dataFormalcheckServiceXtd.getContractAchi(mapp2);
				if(contractAchi2==null) {
					contractAchi2=new BigDecimal(0);
				}
				if(!(checkMonth.compareTo(new BigDecimal(0))==0)) {
					formalcheck.setAveragemoney(sumMoney.divide(checkMonth,2, BigDecimal.ROUND_HALF_UP));
				}else {
					formalcheck.setAveragemoney(new BigDecimal(0));
				}

				formalcheck.setCalMonth(month);
				formalcheck.setCheckmonth(checkMonth);
				formalcheck.setEmployeeid(dictEmployeeEntityXtd.getId());
				formalcheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				formalcheck.setName(dictEmployeeEntityXtd.getName());
				formalcheck.setShouldmoney(shouldMoney);
				formalcheck.setWorkno(dictEmployeeEntityXtd.getWorkno());
				formalcheck.setSummoney(sumMoney);
				formalcheck.setThreemonthmoney(allachi);
				formalcheck.setSigncount(contractCount.add(contractCount2));
				formalcheck.setTwomonthsignmoney(contractAchi.add(contractAchi2));								
				dataFormalcheckServiceXtd.save(formalcheck);
			}else {
				//转正时期的考核的特殊时间已过，按正常3个月考核期算
				List<String> checkTime = CalculateUtils.getCheckTime(month);
				for (String tmonth : checkTime) {
					checkMonth=checkMonth.add(new BigDecimal(1));
					Map<String, Object> map=new HashMap<>();
					map.put("month",tmonth.replace("-", "") );
					map.put("employeeID", employeeId);
					EmpOneMonthAchi monthInfo = dataContractpayDetailServiceXtd.getMonthInfo(map);
					if(monthInfo!=null) {				
						sumMoney=sumMoney.add(monthInfo.getSumMonthMoney());
					}
					EmpMonthShouldAchi shouldInfo = dataFormalcheckServiceXtd.getShouldByMonth(map);
					//这里是累计应收
					if(shouldInfo!=null) {				
						shouldMoney=shouldMoney.add(shouldInfo.getShouldMoney());
					}
				}
				String contractmonth=month.replace("-", "");
				int thisMonth = Integer.parseInt(contractmonth);
				int lastMonth=0;
				int lastlastMonth=0;
				//如果是一月份，则算到去年12月份
				if((thisMonth-1)%100==0) {
					lastMonth=thisMonth-100+11;
				}else {
					lastMonth=thisMonth-1;
				}
				if((thisMonth-2)%100==0) {
					lastlastMonth=thisMonth-100+10;
				}else {
					lastlastMonth=thisMonth-1;
				}
				Map<String, Object> mapp = new HashMap<>();
				mapp.put("month", String.valueOf(thisMonth));
				mapp.put("employeeID", employeeId);
				BigDecimal allAchi = dataContractpayDetailServiceXtd.getAllAchi(mapp);
				if(allAchi==null) {
					allAchi=new BigDecimal(0);
				}
				Map<String, Object> mapp2 = new HashMap<>();
				mapp2.put("month", String.valueOf(lastMonth));
				mapp2.put("employeeID", employeeId);
				BigDecimal allAchi2 = dataContractpayDetailServiceXtd.getAllAchi(mapp2);
				if(allAchi2==null) {
					allAchi2=new BigDecimal(0);
				}
				Map<String, Object> mapp3 = new HashMap<>();
				mapp3.put("month", String.valueOf(lastlastMonth));
				mapp3.put("employeeID", employeeId);
				BigDecimal allAchi3 = dataContractpayDetailServiceXtd.getAllAchi(mapp3);
				if(allAchi3==null) {
					allAchi3=new BigDecimal(0);
				}
				BigDecimal allachi=allAchi.add(allAchi2).add(allAchi3);
				BigDecimal contractCount = dataFormalcheckServiceXtd.getContractCount(mapp);
				if(contractCount==null) {
					contractCount=new BigDecimal(0);
				}
				BigDecimal contractCount2 = dataFormalcheckServiceXtd.getContractCount(mapp2);
				if(contractCount2==null) {
					contractCount2=new BigDecimal(0);
				}
				BigDecimal contractAchi = dataFormalcheckServiceXtd.getContractAchi(mapp);
				if(contractAchi==null) {
					contractAchi=new BigDecimal(0);
				}
				BigDecimal contractAchi2 = dataFormalcheckServiceXtd.getContractAchi(mapp2);
				if(contractAchi2==null) {
					contractAchi2=new BigDecimal(0);
				}
				if(!(checkMonth.compareTo(new BigDecimal(0))==0)) {
					formalcheck.setAveragemoney(sumMoney.divide(checkMonth,2, BigDecimal.ROUND_HALF_UP));
				}else {
					formalcheck.setAveragemoney(new BigDecimal(0));
				}

				formalcheck.setCalMonth(month);
				formalcheck.setCheckmonth(checkMonth);
				formalcheck.setEmployeeid(dictEmployeeEntityXtd.getId());
				formalcheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				formalcheck.setName(dictEmployeeEntityXtd.getName());
				formalcheck.setShouldmoney(shouldMoney);
				formalcheck.setWorkno(dictEmployeeEntityXtd.getWorkno());
				formalcheck.setSummoney(sumMoney);
				formalcheck.setThreemonthmoney(allachi);
				formalcheck.setSigncount(contractCount.add(contractCount2));
				formalcheck.setTwomonthsignmoney(contractAchi.add(contractAchi2));								
				dataFormalcheckServiceXtd.save(formalcheck);
			}
		}	
	}

	/**
	 * 计算首月底薪
	 * @throws ParseException 
	 */
	public static  R calculateSYDX(String month,BigDecimal days,String workNo,BigDecimal divideday,DataDxRecordService dataDxRecordService,DictEmployeeServiceXtd dictEmployeeServiceXtd,String jobno,String employeeId,DictEmployeeEntityXtd employee,SysConfigService sysConfigService,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd, DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd,DataPayrollDxdetailService dataPayrollDxdetailService,DataPayrollServiceXtd dataPayrollServiceXtd) throws ParseException {
		BigDecimal sum = new BigDecimal(0);
		DataPayrollDxdetailEntity dataPayrollDxdetailEntity = new DataPayrollDxdetailEntity();
		dataPayrollDxdetailEntity.setWorkno(workNo);
		dataPayrollDxdetailEntity.setPayrollmonth(month);
		//开通端口的首月底薪（3900）
		String dx = sysConfigService.getValue("firstOfSalary", null);
		BigDecimal sydx = new BigDecimal(dx);
		Integer hasports = employee.getHasFirstPort();//这里更改判断条件，用这个字段判断是否享受首月底薪
		String monthnew = month.replace("-", "");
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		SimpleDateFormat sdf2=new SimpleDateFormat("yyyy-MM");
		//入职时间
		Date inOrgTime = employee.getInorgtime();
		String inOrgTimeString = sdf.format(inOrgTime);
		String inOrgTimeString2 = sdf2.format(inOrgTime);
		//入职年月
		String inTimeNew = inOrgTimeString.replace("-", "").substring(0, 6);
		Integer inTimeInt = Integer.parseInt(inTimeNew);
		//入职的月份
		String inTimeNew2 = inOrgTimeString.replace("-", "").substring(4, 6);	
		Integer inTimeInt2 = Integer.parseInt(inTimeNew2);
		//入职的年份
		String inTimeNew3 = inOrgTimeString.replace("-", "").substring(0, 4);	
		Integer inTimeInt3 = Integer.parseInt(inTimeNew3);
		//入职后的次月
		Integer inTimeNext = 0;
		if(inTimeInt2==12) {
			inTimeNext = inTimeInt+100-11;
		}else {
			inTimeNext = inTimeInt+1;
		}
		//入职后次月的月份
		String inTimeNew4 = inTimeNext.toString().substring(4, 6);
		Integer inTimeInt4 = Integer.parseInt(inTimeNew4);
		//入职后次月的年份
		String inTimeNew5 = inTimeNext.toString().substring(0, 4);	
		Integer inTimeInt5 = Integer.parseInt(inTimeNew5);
		//入职后的第三个月
		Integer inTimeNext2 = 0;
		if((inTimeInt2==11)||(inTimeInt2==12)) {
			//如果是11月或者12月，则顺延到第二年1月或者2月
			inTimeNext2 = inTimeInt+90;
		}else {
			inTimeNext2 = inTimeInt+2;
		}
		//入职当月的天数
		String format = sdf2.format(inOrgTime);
		Calendar calendar = Calendar.getInstance();  
		calendar.setTime(sdf2.parse(format)); 
		Integer dayofmonth =31;
		//当月的天数
		//		Calendar calendarthis = Calendar.getInstance();  
		//		calendarthis.setTime(sdf2.parse(month)); 
		//		Integer dayofthismonth = calendarthis.getActualMaximum(Calendar.DAY_OF_MONTH);
		//当月的出勤天数
		BigDecimal DaysOfAttendance = employee.getDaysOfAttendance();
		//		double DaysOfAttendance = DaysOfAttendance1.doubleValue();
		BigDecimal xs1 = DaysOfAttendance;
		//入职月的应出勤工作日
		BigDecimal xs2 = new BigDecimal(dayofmonth-4);
		//当月的应出勤工作日
		BigDecimal xs3 = days;
		if((hasports==1)&&inOrgTimeString.substring(0, 7).equals(month)) {
			//已开端口
			if(xs1.compareTo(xs2)==-1){
				//当月没算完
				sum = sydx.multiply(xs1).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
				dataPayrollDxdetailEntity.setPayport(sum);
			}else {
				//当月已算完
				sum = sydx;
				dataPayrollDxdetailEntity.setPayport(sum);
			}	
		}else if((hasports==1)&&inTimeNext.toString().equals(monthnew)) {
			//已开端口
			Map<String, Object> map = new HashMap<>();
			map.put("workNo", workNo);
			map.put("hismonth", inTimeInt2);
			map.put("hisyear", inTimeInt3);
			HisEmployeeEntityXtd employeeOld = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map);
			if(employeeOld==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			if(employeeOld.getDaysOfAttendance()==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			if(employeeOld.getHasFirstPort() == null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			BigDecimal DaysOfAttendanceOld = employeeOld.getDaysOfAttendance();
			BigDecimal xs4 = DaysOfAttendanceOld;
			MonthWage dxAll = CalculateUtils.calculateDX(month, employeeId,hisEmployeeServiceXtd,dataDxRecordService,dictEmployeeServiceXtd, sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
			BigDecimal thisDX=dxAll.getThisMonthWage().add(dxAll.getLastMonthWage());
			if(employeeOld.getHasFirstPort() == 1) {
				//上月首月底薪没算完
				if(DaysOfAttendanceOld.compareTo(xs2)==-1) {

					BigDecimal sydxOld=sydx.multiply(xs4).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
					if(!(xs2.subtract(DaysOfAttendanceOld).compareTo(DaysOfAttendance)==1)) {
						//当月已算完
						BigDecimal restOfMonth = DaysOfAttendance.subtract(xs2.subtract(DaysOfAttendanceOld));
						sum = sydx.subtract(sydxOld).add(dxAll.getThisMonthWage().multiply(restOfMonth).divide(xs3,4, BigDecimal.ROUND_HALF_UP)).add(dxAll.getLastMonthWage());
						dataPayrollDxdetailEntity.setPayport(sydx.subtract(sydxOld));
						dataPayrollDxdetailEntity.setPayachi(dxAll.getThisMonthWage().multiply(restOfMonth).divide(xs3,4, BigDecimal.ROUND_HALF_UP).add(dxAll.getLastMonthWage()));
					}
					else {
						//当月没算完
						sum = sydx.multiply(xs1).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
						dataPayrollDxdetailEntity.setPayport(sum);
					}
				}
			}
			if(employeeOld.getHasFirstPort() == 0) {
				Map<String, Object> hismap = new HashMap<>();
				hismap.put("employeeId", employeeId);
				hismap.put("payrollMonth", inOrgTimeString2);
				BigDecimal hisDX = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(hismap).getFirstmonthwage();
				BigDecimal sydxOld=hisDX;
				//上月首月底薪没算完
				if(hisDX.compareTo(sydx)==-1) {
					//首月已上满27天，补发首月剩余的首月底薪
					if(!(xs4.compareTo(xs2)==-1)) {
						sum = sydx.subtract(sydxOld).add(dxAll.getThisMonthWage().multiply(DaysOfAttendance).divide(xs3,4, BigDecimal.ROUND_HALF_UP)).add(dxAll.getLastMonthWage());
						dataPayrollDxdetailEntity.setPayport(sydx.subtract(sydxOld));
						dataPayrollDxdetailEntity.setPayachi(dxAll.getThisMonthWage().multiply(DaysOfAttendance).divide(xs3,4, BigDecimal.ROUND_HALF_UP).add(dxAll.getLastMonthWage()));
					}else if(!(xs2.subtract(DaysOfAttendanceOld).compareTo(DaysOfAttendance)==1)) {
						//当月已算完
						BigDecimal restOfMonth = DaysOfAttendance.subtract(xs2.subtract(DaysOfAttendanceOld));
						sum = sydx.subtract(sydxOld).add(dxAll.getThisMonthWage().multiply(restOfMonth).divide(xs3,4, BigDecimal.ROUND_HALF_UP)).add(dxAll.getLastMonthWage());
						dataPayrollDxdetailEntity.setPayport(sydx.subtract(sydxOld));
						dataPayrollDxdetailEntity.setPayachi(dxAll.getThisMonthWage().multiply(restOfMonth).divide(xs3,4, BigDecimal.ROUND_HALF_UP).add(dxAll.getLastMonthWage()));
					}
					else {
						//当月没算完
						sum = sydx.multiply(xs1).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
						dataPayrollDxdetailEntity.setPayport(sum);
					}
				}else {

				}
			}
		}
		else if((hasports==1)&&inTimeNext2.toString().equals(monthnew)) {
			//已开端口
			//计算入职月的出勤天数
			Map<String, Object> map2 = new HashMap<>();
			map2.put("workNo", workNo);
			map2.put("hismonth", inTimeInt2);
			map2.put("hisyear", inTimeInt3);
			HisEmployeeEntityXtd employeeOld1 = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map2);
			if(employeeOld1==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			if(employeeOld1.getDaysOfAttendance()==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			BigDecimal DaysOfAttendanceOld1 = employeeOld1.getDaysOfAttendance();
			//计算入职后次月的出勤天数
			Map<String, Object> map3 = new HashMap<>();
			map3.put("workNo", workNo);
			map3.put("hismonth", inTimeInt4);
			map3.put("hisyear", inTimeInt5);
			HisEmployeeEntityXtd employeeOld2 = hisEmployeeServiceXtd.queryEmployeeByInOrgTime(map3);
			if(employeeOld2==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			if(employeeOld2.getDaysOfAttendance()==null) {
				return R.error("缺少工号为"+workNo+"员工的人员历史记录");
			}
			BigDecimal DaysOfAttendanceOld2 = employeeOld2.getDaysOfAttendance();
			BigDecimal xs5 = DaysOfAttendanceOld1;
			BigDecimal xs6 = DaysOfAttendanceOld2;
			//当月根据业绩算的底薪
			MonthWage dxAll= CalculateUtils.calculateDX(month, employeeId,hisEmployeeServiceXtd,dataDxRecordService,dictEmployeeServiceXtd, sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
			BigDecimal thisDX2=dxAll.getThisMonthWage().add(dxAll.getLastMonthWage());
			if(employeeOld1.getHasFirstPort() == 0) {
				Map<String, Object> hismap = new HashMap<>();
				hismap.put("employeeId", employeeId);
				hismap.put("payrollMonth", inOrgTimeString2);
				BigDecimal hisDX = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(hismap).getFirstmonthwage();
				BigDecimal sydxOld1=hisDX;
				//首月底薪没算完
				if(hisDX.compareTo(sydx)==-1) {
					//入职首月和次月加起来没算完首月底薪，这个月继续算
					if((xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2).compareTo(new BigDecimal(0))==1)&&!(xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2).compareTo(DaysOfAttendance)==1)) {
						//入职次月的底薪
						BigDecimal sydxOld2=sydx.multiply(xs6).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
						//除去首月27天的出勤，剩余的出勤天数
						BigDecimal restOfMonth2 =DaysOfAttendance.subtract(xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2));
						//本月底薪
						sum = sydx.subtract(sydxOld1).subtract(sydxOld2).add(dxAll.getThisMonthWage().multiply(restOfMonth2).divide(xs3,4, BigDecimal.ROUND_HALF_UP)).add(dxAll.getLastMonthWage());
						dataPayrollDxdetailEntity.setPayport(sydx.subtract(sydxOld1).subtract(sydxOld2));
						dataPayrollDxdetailEntity.setPayachi(dxAll.getThisMonthWage().multiply(restOfMonth2).divide(xs3,4, BigDecimal.ROUND_HALF_UP).add(dxAll.getLastMonthWage()));
					}
				}else {

				}
			}
			if(employeeOld1.getHasFirstPort() == 1) {
				//入职首月和次月加起来没算完首月底薪，这个月继续算
				if((xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2).compareTo(new BigDecimal(0))==1)&&!(xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2).compareTo(DaysOfAttendance)==1)) {
					//入职月的底薪
					BigDecimal sydxOld1=sydx.multiply(xs5).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
					//入职次月的底薪
					BigDecimal sydxOld2=sydx.multiply(xs6).divide(xs2,4, BigDecimal.ROUND_HALF_UP);
					//除去首月27天的出勤，剩余的出勤天数
					BigDecimal restOfMonth2 =DaysOfAttendance.subtract(xs2.subtract(DaysOfAttendanceOld1).subtract(DaysOfAttendanceOld2));
					//本月底薪
					sum = sydx.subtract(sydxOld1).subtract(sydxOld2).add(dxAll.getThisMonthWage().multiply(restOfMonth2).divide(xs3,4, BigDecimal.ROUND_HALF_UP)).add(dxAll.getLastMonthWage());
					dataPayrollDxdetailEntity.setPayport(sydx.subtract(sydxOld1).subtract(sydxOld2));
					dataPayrollDxdetailEntity.setPayachi(dxAll.getThisMonthWage().multiply(restOfMonth2).divide(xs3,4, BigDecimal.ROUND_HALF_UP).add(dxAll.getLastMonthWage()));
				}
			}
		}
		else if((hasports==0)&&inOrgTimeString.substring(0, 7).equals(month)) {
			MonthWage dxAll = CalculateUtils.calculateDX(month, employeeId,hisEmployeeServiceXtd,dataDxRecordService,dictEmployeeServiceXtd, sysConfigService, dataContractpayDetailServiceXtd, dataEmployeeachiRecordServiceXtd);
			BigDecimal dxofnoports =dxAll.getThisMonthWage().add(dxAll.getLastMonthWage());
			if("01".equals(jobno)&&dxofnoports.compareTo(new BigDecimal(1200))==0) {
				dxofnoports = new BigDecimal(1500);
			}
			sum = dxofnoports.multiply(xs1).divide(xs3,4, BigDecimal.ROUND_HALF_UP);
			dataPayrollDxdetailEntity.setPayachi(sum);
		}
		dataPayrollDxdetailService.save(dataPayrollDxdetailEntity);
		return R.ok().put("sum", sum);
	}
	/**
	 * 找02职级的所有同组推荐树
	 * @return
	 */
	static List<DictEmployeeEntityXtd> allRecList = new ArrayList<DictEmployeeEntityXtd>();
	public static  List<DictEmployeeEntityXtd> getRecList(String workNo,DictEmployeeServiceXtd dictEmployeeServiceXtd){
		DictEmployeeEntityXtd listByWorkNo = dictEmployeeServiceXtd.getListByWorkNo(workNo);
		String deptno2 = listByWorkNo.getDeptno();
		List<DictEmployeeEntityXtd> queryRecommender = dictEmployeeServiceXtd.queryRecommender(workNo);
		for (DictEmployeeEntityXtd dictEmployeeEntityXtd : queryRecommender) {
			String workno2 = dictEmployeeEntityXtd.getWorkno();
			String deptno = dictEmployeeEntityXtd.getDeptno();
			//推荐人在同一组
			if(deptno2.equals(deptno)) {
				allRecList.add(dictEmployeeEntityXtd);
				getRecList(workno2, dictEmployeeServiceXtd);
			}
		}
		return allRecList;

	};
	/**
	 * 保存分行预警信息
	 */
	public static void saveFHcheck(String month,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataDirectcheckServiceXtd dataDirectcheckServiceXtd,DataBranchcheckServiceXtd dataBranchcheckServiceXtd) {
		List<DictEmployeeEntityXtd> listByJobNo = dictEmployeeServiceXtd.getListByJobNo("06");
		List<DictEmployeeEntityXtd> listByJobNo1 = dictEmployeeServiceXtd.getListByJobNo("08");
		List<DictEmployeeEntityXtd> listByJobNo2 = dictEmployeeServiceXtd.getListByJobNo("09");
		List<DictEmployeeEntityXtd> listByJobNo3 = dictEmployeeServiceXtd.getListByJobNo("10");
		listByJobNo.addAll(listByJobNo3);
		listByJobNo.addAll(listByJobNo2);
		listByJobNo.addAll(listByJobNo1);
		if(listByJobNo!=null) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : listByJobNo) {
				DataBranchcheckEntityXtd dataCheck=new DataBranchcheckEntityXtd();
				//任职时间
				Integer jobTime=1;
				//直接推荐人个数
				Integer recommender=0;
				//直接推荐02个数
				Integer recommender02=0;
				//直辖组人数
				Integer totalMember=0;
				//直接育成主管数
				Integer bredDirector=0;
				//间接育成主管数
				Integer bredIndirector=0;
				//直接育成分行数
				Integer bredBranch=0;
				//间接育成分行数
				Integer bredInbranch=0;
				BigDecimal groupSum=new BigDecimal(0);
				BigDecimal totalMonth=new BigDecimal(0);
				String jobNo = dictEmployeeEntityXtd.getJobNo();
				String workno = dictEmployeeEntityXtd.getWorkno();
				String employeeId = dictEmployeeEntityXtd.getId();
				Map<String,Object> map=new HashMap<>();
				map.put("jobNo", jobNo);
				map.put("workNo",workno );
				//获得直辖组总人数
				Map<String,Object> depmap=new HashMap<>();
				depmap.put("workNo", workno);
				depmap.put("deptNoFirst", "Z");
				DictDepartmentEntityXtd depZ = dictDepartmentServiceXtd.getDepNo(depmap);
				String deptNo = depZ.getDeptNo();
				List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(deptNo);
				totalMember=totalMember+queryDeptNoXtd.size();

				HisEmployeeEntityXtd oldHis = hisEmployeeServiceXtd.getOldHis(map);
				if(oldHis!=null) {
					String[] split = month.split("-");
					Integer hisyear = oldHis.getHisyear();
					Integer hismonth = oldHis.getHismonth();
					//这里得到此职级的任职时间
					jobTime=(Integer.parseInt(split[0])-hisyear)*12+Integer.parseInt(split[1])-hismonth;			
				}
				//获取要考核的月份
				if("06".equals(jobNo)) {
					List<String> checkTime = CalculateUtils.getCheckTime(month);
					for (String string : checkTime) {
						//判断考核月是不是在当前月份之内
						if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
							//累计月份
							totalMonth=totalMonth.add(new BigDecimal(1));					
							Map<String,Object> mapp=new HashMap<>();
							mapp.put("month", string.replace("-", ""));
							mapp.put("directorNo", workno);
							BigDecimal groupAchiByWorkNo = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp);
							if(groupAchiByWorkNo!=null) {
								groupSum=groupSum.add(groupAchiByWorkNo);
							}

							Map<String,Object> mapp3=new HashMap<>();
							mapp3.put("directorNo", workno);
							List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(mapp3);
							for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
								Map<String,Object> mapp5=new HashMap<>();
								mapp5.put("month", string.replace("-", ""));
								mapp5.put("directorNo", dictEmployeeEntityXtd2.getWorkno());
								BigDecimal groupAchiByWorkNo2 = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp5);
								if(groupAchiByWorkNo2!=null) {
									groupSum=groupSum.add(groupAchiByWorkNo2);
								}

							}
						}
					}
				}else {
					//已经是分行
					List<String> checkTime = CalculateUtils.getCheckTime(month);
					for (String string : checkTime) {
						//判断考核月是不是在当前月份之内
						if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
							//累计月份
							totalMonth=totalMonth.add(new BigDecimal(1));					

							Map<String,Object> mapp2=new HashMap<>();
							mapp2.put("month", string.replace("-", ""));
							mapp2.put("branchNo", workno);
							BigDecimal groupAchiByWorkNo = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
							if(groupAchiByWorkNo!=null) {
								groupSum=groupSum.add(groupAchiByWorkNo);
							}

						}
					}
					Map<String,Object> mapp3=new HashMap<>();

					mapp3.put("directorBredNo", workno);
					List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(mapp3);
					if(queryBredNo!=null) {
						bredDirector=queryBredNo.size();
					}

					for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
						String workno2 = dictEmployeeEntityXtd2.getWorkno();
						Map<String,Object> mapp4=new HashMap<>();

						mapp4.put("directorBredNo", workno2);
						List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
						if(queryBredNo2!=null) {
							bredIndirector=bredIndirector+queryBredNo2.size();
						}
					}
					Map<String,Object> mapp4=new HashMap<>();

					mapp4.put("branchBredNo", workno);
					List<DictEmployeeEntityXtd> queryBredNo3 = dictEmployeeServiceXtd.queryBredNo(mapp4);
					if(queryBredNo3!=null) {
						bredBranch=queryBredNo3.size();
					}

					for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
						String workno2 = dictEmployeeEntityXtd2.getWorkno();
						Map<String,Object> mapp5=new HashMap<>();

						mapp5.put("branchBredNo", workno2);
						List<DictEmployeeEntityXtd> queryBredNo4 = dictEmployeeServiceXtd.queryBredNo(mapp5);
						if(queryBredNo4!=null) {
							bredInbranch=bredInbranch+queryBredNo4.size();
						}
					}

				}
				List<DictEmployeeEntityXtd> queryRecommender = dictEmployeeServiceXtd.queryRecommender(workno);
				recommender=queryRecommender.size();
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryRecommender) {
					String jobNo2 = dictEmployeeEntityXtd2.getJobNo();
					if("11.0".equals(jobNo2)) {
						jobNo2="11";
					}
					if("12.0".equals(jobNo2)) {
						jobNo2="12";
					}
					if("13.0".equals(jobNo2)) {
						jobNo2="13";
					}
					if("14.0".equals(jobNo2)) {
						jobNo2="14";
					}
					if("15.0".equals(jobNo2)) {
						jobNo2="15";
					}
					if("16.0".equals(jobNo2)) {
						jobNo2="16";
					}
					if("17.0".equals(jobNo2)) {
						jobNo2="17";
					}
					if("18.0".equals(jobNo2)) {
						jobNo2="18";
					}
					if("02".equals(jobNo2)) {
						recommender02=recommender02+1;
					}
				}

				dataCheck.setCaltime(month);
				dataCheck.setDirectbredzg(bredDirector);
				dataCheck.setDirectrec(recommender);
				dataCheck.setEmployeeid(employeeId);
				dataCheck.setGroupaverage(groupSum.multiply(totalMonth));
				dataCheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				dataCheck.setJobtime(jobTime);
				dataCheck.setName(dictEmployeeEntityXtd.getName());
				dataCheck.setNormalrec(recommender02);
				dataCheck.setTotalbredzg(bredIndirector+bredDirector);
				dataCheck.setTotalmember(totalMember);
				dataCheck.setWorkno(workno);
				dataCheck.setDirectbredfh(bredBranch);
				dataCheck.setTotalbredfh(bredBranch+bredInbranch);
				dataBranchcheckServiceXtd.save(dataCheck);

			}
		}
	}
	/**
	 * 保存主管预警信息
	 */
	public static void saveZGcheck(String month,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataDirectcheckServiceXtd dataDirectcheckServiceXtd) {
		List<DictEmployeeEntityXtd> listByJobNo = dictEmployeeServiceXtd.getListByJobNo("02");
		List<DictEmployeeEntityXtd> listByJobNo1 = dictEmployeeServiceXtd.getListByJobNo("04");
		List<DictEmployeeEntityXtd> listByJobNo2 = dictEmployeeServiceXtd.getListByJobNo("05");
		List<DictEmployeeEntityXtd> listByJobNo3 = dictEmployeeServiceXtd.getListByJobNo("06");
		listByJobNo.addAll(listByJobNo3);
		listByJobNo.addAll(listByJobNo2);
		listByJobNo.addAll(listByJobNo1);
		if(listByJobNo!=null) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : listByJobNo) {
				DataDirectcheckEntityXtd dataCheck=new DataDirectcheckEntityXtd();
				//任职时间
				Integer jobTime=1;
				//直接推荐人个数
				Integer recommender=0;
				//直接推荐02个数
				Integer recommender02=0;
				//直辖组人数
				Integer totalMember=0;
				//直接育成主管数
				Integer bredDirector=0;
				//间接育成主管数
				Integer bredIndirector=0;
				BigDecimal sum=new BigDecimal(0);
				BigDecimal groupSum=new BigDecimal(0);
				BigDecimal totalMonth=new BigDecimal(0);
				String jobNo = dictEmployeeEntityXtd.getJobNo();
				String workno = dictEmployeeEntityXtd.getWorkno();
				String employeeId = dictEmployeeEntityXtd.getId();
				Map<String,Object> map=new HashMap<>();
				map.put("jobNo", jobNo);
				map.put("workNo",workno );				
				HisEmployeeEntityXtd oldHis = hisEmployeeServiceXtd.getOldHis(map);
				if(oldHis!=null) {
					String[] split = month.split("-");
					Integer hisyear = oldHis.getHisyear();
					Integer hismonth = oldHis.getHismonth();
					//这里得到此职级的任职时间
					jobTime=(Integer.parseInt(split[0])-hisyear)*12+Integer.parseInt(split[1])-hismonth;			
				}
				//获取要考核的月份
				if("02".equals(jobNo)) {
					List<String> checkTime = CalculateUtils.getCheckTime(month);
					for (String string : checkTime) {
						//判断考核月是不是在当前月份之内
						if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
							//累计月份
							totalMonth=totalMonth.add(new BigDecimal(1));					
							Map<String,Object> mapp=new HashMap<>();
							mapp.put("month", string.replace("-", ""));
							mapp.put("employeeID", employeeId);
							EmpOneMonthAchi monthInfo = dataContractpayDetailServiceXtd.getMonthInfo(mapp);
							if(monthInfo!=null) {
								BigDecimal sumMonthMoney = monthInfo.getSumMonthMoney();
								//累计业绩
								sum=sum.add(sumMonthMoney);
							}
							//这里是02职级算主管晋升，推荐人所有，包括直接推荐，间接推荐，和各种推荐							
							List<DictEmployeeEntityXtd> recList = CalculateUtils.getRecList(workno, dictEmployeeServiceXtd);
							totalMember=recList.size();
							for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : recList) {

								String id = dictEmployeeEntityXtd2.getId();
								Map<String,Object> mapp2=new HashMap<>();
								mapp2.put("month", string.replace("-", ""));
								mapp2.put("employeeID", id);
								//推荐人的已收业绩
								EmpOneMonthAchi monthInfo2 = dataContractpayDetailServiceXtd.getMonthInfo(mapp2);
								if(monthInfo2!=null) {
									BigDecimal sumMonthMoney = monthInfo2.getSumMonthMoney();
									//组累计业绩
									groupSum=groupSum.add(sumMonthMoney);
								}
							}
						}
					}
				}else {
					//已经是主管
					List<String> checkTime = CalculateUtils.getCheckTime(month);
					//获得直辖组总人数
					Map<String,Object> depmap=new HashMap<>();
					depmap.put("workNo", workno);
					depmap.put("deptNoFirst", "Z");
					DictDepartmentEntityXtd depZ = dictDepartmentServiceXtd.getDepNo(depmap);
					String deptNo = depZ.getDeptNo();
					List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(deptNo);
					totalMember=totalMember+queryDeptNoXtd.size();
					for (String string : checkTime) {
						//判断考核月是不是在当前月份之内
						if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
							//累计月份
							totalMonth=totalMonth.add(new BigDecimal(1));					
							Map<String,Object> mapp=new HashMap<>();
							mapp.put("month", string.replace("-", ""));
							mapp.put("employeeID", employeeId);
							EmpOneMonthAchi monthInfo = dataContractpayDetailServiceXtd.getMonthInfo(mapp);
							if(monthInfo!=null) {
								BigDecimal sumMonthMoney = monthInfo.getSumMonthMoney();
								//累计业绩
								sum=sum.add(sumMonthMoney);
							}
							Map<String,Object> mapp2=new HashMap<>();
							mapp2.put("month", string.replace("-", ""));
							mapp2.put("directorNo", workno);
							BigDecimal groupAchiByWorkNo = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
							if(groupAchiByWorkNo!=null) {
								groupSum=groupSum.add(groupAchiByWorkNo);
							}
						}
					}
					Map<String,Object> mapp3=new HashMap<>();

					mapp3.put("directorBredNo", workno);
					List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(mapp3);
					if(queryBredNo!=null) {
						bredDirector=queryBredNo.size();
					}
					for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
						String workno2 = dictEmployeeEntityXtd2.getWorkno();
						Map<String,Object> mapp4=new HashMap<>();

						mapp4.put("directorBredNo", workno2);
						List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
						if(queryBredNo2!=null) {
							bredIndirector=bredIndirector+queryBredNo2.size();
						}
					}

				}
				List<DictEmployeeEntityXtd> queryRecommender = dictEmployeeServiceXtd.queryRecommender(workno);
				recommender=queryRecommender.size();
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryRecommender) {
					String jobNo2 = dictEmployeeEntityXtd2.getJobNo();
					if("02".equals(jobNo2)) {
						recommender02=recommender02+1;
					}
				}
				dataCheck.setAverageachi(sum.multiply(totalMonth));
				dataCheck.setCaltime(month);
				dataCheck.setDirectbredzg(bredDirector);
				dataCheck.setDirectrec(recommender);
				dataCheck.setEmployeeid(employeeId);
				dataCheck.setGroupaverage(groupSum.multiply(totalMonth));
				dataCheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				dataCheck.setJobtime(jobTime);
				dataCheck.setName(dictEmployeeEntityXtd.getName());
				dataCheck.setNormalrec(recommender02);
				dataCheck.setTotalbredzg(bredIndirector);
				dataCheck.setTotalmember(totalMember);
				dataCheck.setWorkno(workno);
				dataDirectcheckServiceXtd.save(dataCheck);
			}
		}

	}
	/**
	 * 保存分行预警信息
	 */
	public static void saveQYcheck(String month,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataDirectcheckServiceXtd dataDirectcheckServiceXtd,DataAreacheckServiceXtd dataAreacheckServiceXtd) {
		List<DictEmployeeEntityXtd> listByJobNo = dictEmployeeServiceXtd.getListByJobNo("10");
		List<DictEmployeeEntityXtd> listByJobNo1 = dictEmployeeServiceXtd.getListByJobNo("12");
		List<DictEmployeeEntityXtd> listByJobNo2 = dictEmployeeServiceXtd.getListByJobNo("13");
		List<DictEmployeeEntityXtd> listByJobNo3 = dictEmployeeServiceXtd.getListByJobNo("14");
		listByJobNo.addAll(listByJobNo3);
		listByJobNo.addAll(listByJobNo2);
		listByJobNo.addAll(listByJobNo1);
		if(listByJobNo!=null) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : listByJobNo) {
				DataAreacheckEntityXtd dataCheck=new DataAreacheckEntityXtd();
				//任职时间
				Integer jobTime=1;
				//直接推荐人个数
				Integer recommender=0;
				//直接推荐02个数
				Integer recommender02=0;
				//直辖组人数
				Integer totalMember=0;
				//直接育成主管数
				Integer bredDirector=0;
				//间接育成主管数
				Integer bredIndirector=0;
				//直接育成分行数
				Integer bredBranch=0;
				//间接育成分行数
				Integer bredInbranch=0;
				//直接育成分行数
				Integer bredArea=0;
				//间接育成分行数
				Integer bredInarea=0;
				BigDecimal groupSum=new BigDecimal(0);
				BigDecimal totalMonth=new BigDecimal(0);
				String jobNo = dictEmployeeEntityXtd.getJobNo();
				String workno = dictEmployeeEntityXtd.getWorkno();
				String employeeId = dictEmployeeEntityXtd.getId();
				Map<String,Object> map=new HashMap<>();
				map.put("jobNo", jobNo);
				map.put("workNo",workno );				
				HisEmployeeEntityXtd oldHis = hisEmployeeServiceXtd.getOldHis(map);
				//获得直辖组总人数
				Map<String,Object> depmap=new HashMap<>();
				depmap.put("workNo", workno);
				depmap.put("deptNoFirst", "Z");
				DictDepartmentEntityXtd depZ = dictDepartmentServiceXtd.getDepNo(depmap);
				String deptNo = depZ.getDeptNo();
				List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(deptNo);
				totalMember=totalMember+queryDeptNoXtd.size();

				if(oldHis!=null) {
					String[] split = month.split("-");
					Integer hisyear = oldHis.getHisyear();
					Integer hismonth = oldHis.getHismonth();
					//这里得到此职级的任职时间
					jobTime=(Integer.parseInt(split[0])-hisyear)*12+Integer.parseInt(split[1])-hismonth;			
				}				
				//已是区域
				List<String> checkTime = CalculateUtils.getCheckTime(month);
				for (String string : checkTime) {
					//判断考核月是不是在当前月份之内
					if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
						//累计月份
						totalMonth=totalMonth.add(new BigDecimal(1));					

						Map<String,Object> mapp2=new HashMap<>();
						mapp2.put("month", string.replace("-", ""));
						mapp2.put("branchNo", workno);
						BigDecimal groupAchiByWorkNo = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
						if(groupAchiByWorkNo!=null) {
							groupSum=groupSum.add(groupAchiByWorkNo);
						}

					}
				}
				//主管直接育成
				Map<String,Object> mapp3=new HashMap<>();
				mapp3.put("directorBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(mapp3);
				if(queryBredNo!=null) {
					bredDirector=queryBredNo.size();
				}
				//主管间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp4=new HashMap<>();
					mapp4.put("directorBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
					if(queryBredNo2!=null) {
						bredIndirector=bredIndirector+queryBredNo2.size();
					}
				}

				//分行直接育成
				Map<String,Object> mapp4=new HashMap<>();
				mapp4.put("branchBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
				if(queryBredNo2!=null) {
					bredBranch=queryBredNo2.size();
				}
				//分行间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp5=new HashMap<>();

					mapp5.put("branchBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo4 = dictEmployeeServiceXtd.queryBredNo(mapp5);
					if(queryBredNo4!=null) {
						bredInbranch=bredInbranch+queryBredNo4.size();
					}
				}

				//区域直接育成
				Map<String,Object> mapp5=new HashMap<>();
				mapp5.put("areaBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo3 = dictEmployeeServiceXtd.queryBredNo(mapp5);
				if(queryBredNo3!=null) {
					bredArea=queryBredNo3.size();
				}
				//区域间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo3) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp6=new HashMap<>();

					mapp6.put("areaBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo5 = dictEmployeeServiceXtd.queryBredNo(mapp6);
					if(queryBredNo5!=null) {
						bredInarea=bredInarea+queryBredNo5.size();
					}
				}


				List<DictEmployeeEntityXtd> queryRecommender = dictEmployeeServiceXtd.queryRecommender(workno);
				recommender=queryRecommender.size();
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryRecommender) {
					String jobNo2 = dictEmployeeEntityXtd2.getJobNo();
					if("02".equals(jobNo2)) {
						recommender02=recommender02+1;
					}
				}

				dataCheck.setCaltime(month);
				dataCheck.setDirectbredzg(bredDirector);
				dataCheck.setDirectrec(recommender);
				dataCheck.setEmployeeid(employeeId);
				dataCheck.setGroupaverage(groupSum.multiply(totalMonth));
				dataCheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				dataCheck.setJobtime(jobTime);
				dataCheck.setName(dictEmployeeEntityXtd.getName());
				dataCheck.setNormalrec(recommender02);
				dataCheck.setTotalbredzg(bredIndirector+bredDirector);
				dataCheck.setTotalmember(totalMember);
				dataCheck.setWorkno(workno);
				dataCheck.setDirectbredfh(bredBranch);
				dataCheck.setTotalbredfh(bredBranch+bredInbranch);
				dataCheck.setDirectbredqy(bredArea);
				dataCheck.setTotalbredqy(bredInarea+bredArea);
				dataAreacheckServiceXtd.save(dataCheck);

			}
		}

	}

	/**
	 * 保存大区预警信息
	 */
	public static void saveDQcheck(String month,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd,HisEmployeeServiceXtd hisEmployeeServiceXtd,DataDirectcheckServiceXtd dataDirectcheckServiceXtd,DataBigareacheckServiceXtd dataBigareacheckServiceXtd) {
		List<DictEmployeeEntityXtd> listByJobNo = dictEmployeeServiceXtd.getListByJobNo("14");
		List<DictEmployeeEntityXtd> listByJobNo1 = dictEmployeeServiceXtd.getListByJobNo("16");
		List<DictEmployeeEntityXtd> listByJobNo2 = dictEmployeeServiceXtd.getListByJobNo("17");
		List<DictEmployeeEntityXtd> listByJobNo3 = dictEmployeeServiceXtd.getListByJobNo("18");
		listByJobNo.addAll(listByJobNo3);
		listByJobNo.addAll(listByJobNo2);
		listByJobNo.addAll(listByJobNo1);
		if(listByJobNo!=null) {
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : listByJobNo) {
				DataBigareacheckEntityXtd dataCheck=new DataBigareacheckEntityXtd();
				//任职时间
				Integer jobTime=1;
				//直接推荐人个数
				Integer recommender=0;
				//直接推荐02个数
				Integer recommender02=0;
				//直辖组人数
				Integer totalMember=0;
				//直接育成主管数
				Integer bredDirector=0;
				//间接育成主管数
				Integer bredIndirector=0;
				//直接育成分行数
				Integer bredBranch=0;
				//间接育成分行数
				Integer bredInbranch=0;
				//直接育成区域数
				Integer bredArea=0;
				//间接育成区域数
				Integer bredInarea=0;
				//直接育成大区数
				Integer bredBigarea=0;
				//间接育成大区数
				Integer bredInbigarea=0;
				BigDecimal groupSum=new BigDecimal(0);
				BigDecimal totalMonth=new BigDecimal(0);
				String jobNo = dictEmployeeEntityXtd.getJobNo();
				String workno = dictEmployeeEntityXtd.getWorkno();
				String employeeId = dictEmployeeEntityXtd.getId();
				Map<String,Object> map=new HashMap<>();
				map.put("jobNo", jobNo);
				map.put("workNo",workno );				
				HisEmployeeEntityXtd oldHis = hisEmployeeServiceXtd.getOldHis(map);
				//获得直辖组总人数
				Map<String,Object> depmap=new HashMap<>();
				depmap.put("workNo", workno);
				depmap.put("deptNoFirst", "Z");
				DictDepartmentEntityXtd depZ = dictDepartmentServiceXtd.getDepNo(depmap);
				String deptNo = depZ.getDeptNo();
				List<DictEmployeeEntityXtd> queryDeptNoXtd = dictEmployeeServiceXtd.queryDeptNoXtd(deptNo);
				totalMember=totalMember+queryDeptNoXtd.size();

				if(oldHis!=null) {
					String[] split = month.split("-");
					Integer hisyear = oldHis.getHisyear();
					Integer hismonth = oldHis.getHismonth();
					//这里得到此职级的任职时间
					jobTime=(Integer.parseInt(split[0])-hisyear)*12+Integer.parseInt(split[1])-hismonth;			
				}				
				//已经是分行
				List<String> checkTime = CalculateUtils.getCheckTime(month);
				for (String string : checkTime) {
					//判断考核月是不是在当前月份之内
					if(Integer.parseInt(string.replace("-", ""))<=Integer.parseInt(month.replace("-", ""))) {
						//累计月份
						totalMonth=totalMonth.add(new BigDecimal(1));					

						Map<String,Object> mapp2=new HashMap<>();
						mapp2.put("month", string.replace("-", ""));
						mapp2.put("branchNo", workno);
						BigDecimal groupAchiByWorkNo = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
						if(groupAchiByWorkNo!=null) {
							groupSum=groupSum.add(groupAchiByWorkNo);
						}
					}
				}
				//主管直接育成
				Map<String,Object> mapp3=new HashMap<>();
				mapp3.put("directorBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(mapp3);
				if(queryBredNo!=null) {
					bredDirector=queryBredNo.size();
				}
				//主管间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp4=new HashMap<>();
					mapp4.put("directorBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
					if(queryBredNo2!=null) {
						bredIndirector=bredIndirector+queryBredNo2.size();
					}
				}

				//分行直接育成
				Map<String,Object> mapp4=new HashMap<>();
				mapp4.put("branchBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(mapp4);
				if(queryBredNo2!=null) {
					bredBranch=queryBredNo2.size();
				}
				//分行间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp5=new HashMap<>();

					mapp5.put("branchBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo4 = dictEmployeeServiceXtd.queryBredNo(mapp5);
					if(queryBredNo4!=null) {
						bredInbranch=bredInbranch+queryBredNo4.size();
					}
				}

				//区域直接育成
				Map<String,Object> mapp5=new HashMap<>();
				mapp5.put("areaBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo3 = dictEmployeeServiceXtd.queryBredNo(mapp5);
				if(queryBredNo3!=null) {
					bredArea=queryBredNo3.size();
				}
				//区域间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo3) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp6=new HashMap<>();

					mapp6.put("areaBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo5 = dictEmployeeServiceXtd.queryBredNo(mapp6);
					if(queryBredNo5!=null) {
						bredInarea=bredInarea+queryBredNo5.size();
					}
				}

				//大区直接育成
				Map<String,Object> mapp6=new HashMap<>();
				mapp6.put("bigAreaBredNo", workno);
				List<DictEmployeeEntityXtd> queryBredNo4 = dictEmployeeServiceXtd.queryBredNo(mapp6);
				if(queryBredNo4!=null) {
					bredBigarea=queryBredNo4.size();
				}
				//大区间接育成
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryBredNo4) {
					String workno2 = dictEmployeeEntityXtd2.getWorkno();
					Map<String,Object> mapp7=new HashMap<>();

					mapp7.put("bigAreaBredNo", workno2);
					List<DictEmployeeEntityXtd> queryBredNo5 = dictEmployeeServiceXtd.queryBredNo(mapp7);
					if(queryBredNo5!=null) {
						bredInbigarea=bredInbigarea+queryBredNo5.size();
					}

				}


				List<DictEmployeeEntityXtd> queryRecommender = dictEmployeeServiceXtd.queryRecommender(workno);
				recommender=queryRecommender.size();
				for (DictEmployeeEntityXtd dictEmployeeEntityXtd2 : queryRecommender) {
					String jobNo2 = dictEmployeeEntityXtd2.getJobNo();
					if("02".equals(jobNo2)) {
						recommender02=recommender02+1;
					}
				}

				dataCheck.setCaltime(month);
				dataCheck.setDirectbredzg(bredDirector);
				dataCheck.setDirectrec(recommender);
				dataCheck.setEmployeeid(employeeId);
				dataCheck.setGroupaverage(groupSum.multiply(totalMonth));
				dataCheck.setJobno(dictEmployeeEntityXtd.getJobNo());
				dataCheck.setJobtime(jobTime);
				dataCheck.setName(dictEmployeeEntityXtd.getName());
				dataCheck.setNormalrec(recommender02);
				dataCheck.setTotalbredzg(bredIndirector+bredDirector);
				dataCheck.setTotalmember(totalMember);
				dataCheck.setWorkno(workno);
				dataCheck.setDirectbredfh(bredBranch);
				dataCheck.setTotalbredfh(bredBranch+bredInbranch);
				dataCheck.setDirectbredqy(bredArea);
				dataCheck.setTotalbredqy(bredInarea+bredArea);
				dataCheck.setDirectbreddq(bredBigarea);
				dataCheck.setTotalbreddq(bredInbigarea+bredBigarea);
				dataBigareacheckServiceXtd.save(dataCheck);

			}
		}
	}
	/**
	 * 根据年月删除信息
	 */
	public static void cancelCal(String month,DataCalculateKService dataCalculateKService,DataDxRecordService dataDxRecordService,DataTeampayServiceXtd dataTeampayServiceXtd,DataPayrollDxdetailServiceXtd dataPayrollDxdetailServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,DataRecommendServiceXtd dataRecommendServiceXtd,DataAreaachiRecordServiceXtd dataAreaachiRecordServiceXtd,DataAreacheckServiceXtd dataAreacheckServiceXtd,DataBigareaachiRecordServiceXtd dataBigareaachiRecordServiceXtd,DataBigareacheckServiceXtd dataBigareacheckServiceXtd,DataBranchachiRecordServiceXtd dataBranchachiRecordServiceXtd,DataBranchcheckServiceXtd dataBranchcheckServiceXtd,DataDirectcheckServiceXtd dataDirectcheckServiceXtd,DataDirectorachiRecordServiceXtd dataDirectorachiRecordServiceXtd,DataEmployeeachiRecordServiceXtd dataEmployeeachiRecordServiceXtd,DataFormalcheckServiceXtd dataFormalcheckServiceXtd,DataPayrollServiceXtd dataPayrollServiceXtd,DataRecommendRecordServiceXtd dataRecommendRecordServiceXtd) {
		dataAreaachiRecordServiceXtd.deleteByMonth(month);
		dataAreacheckServiceXtd.deleteByMonth(month);
		dataBigareaachiRecordServiceXtd.deleteByMonth(month);
		dataBigareacheckServiceXtd.deleteByMonth(month);
		dataBranchachiRecordServiceXtd.deleteByMonth(month);
		dataBranchcheckServiceXtd.deleteByMonth(month);
		dataDirectcheckServiceXtd.deleteByMonth(month);
		dataDirectorachiRecordServiceXtd.deleteByMonth(month);
		dataEmployeeachiRecordServiceXtd.deleteByMonth(month);
		dataFormalcheckServiceXtd.deleteByMonth(month);
		dataPayrollServiceXtd.deleteByMonth(month);
		dataRecommendRecordServiceXtd.deleteByMonth(month);	
		dataRecommendServiceXtd.deleteByCalTime(month);
		dataMonthdirectServiceXtd.deleteByCalTime(month);
		dataPayrollDxdetailServiceXtd.deleteByCalTime(month);
		dataTeampayServiceXtd.deleteByCalTime(month);
		dataDxRecordService.deleteByMonth(month);
		dataCalculateKService.deleteByMonth(month);
	}
	/**
	 * 每个分行的总支出
	 * @throws ParseException 
	 */
	public static void saveFHcost(String month,DataTeampayServiceImplXtd dataTeampayServiceImplXtd,DataRecommendServiceXtd dataRecommendServiceXtd,DataContractpayDetailServiceXtd dataContractpayDetailServiceXtd,DataMonthdirectServiceXtd dataMonthdirectServiceXtd,SysConfigService sysConfigService,DictEmployeeServiceXtd dictEmployeeServiceXtd,DictDepartmentServiceXtd dictDepartmentServiceXtd,DataPayrollServiceXtd dataPayrollServiceXtd,DataContractXtdServiceXtd dataContractXtdServiceXtd) throws ParseException {
		//所有分行
		List<DictDepartmentEntityXtd> fhInfo = dictDepartmentServiceXtd.getFHInfo();
		for (DictDepartmentEntityXtd dictDepartmentEntityXtd : fhInfo) {
			//BigDecimal paySum=new BigDecimal(0);
			String employeeID = dictDepartmentEntityXtd.getEmployeeID();
			//分行负责人
			DictEmployeeEntityXtd leader = dictEmployeeServiceXtd.getListByWorkNo(employeeID);
			DataTeampayEntityXtd teamPay=new DataTeampayEntityXtd();
			//员工总支出
			BigDecimal employeePay=new BigDecimal(0);
			//分行直接管理津贴
			BigDecimal branchDirect=new BigDecimal(0);
			//本分行的间接管理津贴
			BigDecimal branchIndirect=new BigDecimal(0);
			//区域直接管理津贴由它的分行承担部分
			BigDecimal areaDirect=new BigDecimal(0);
			//区域间接管理津贴由本区域经理直属分行承担部分
			BigDecimal areaIndirect=new BigDecimal(0);
			//大区直接管理津贴由它的分行承担部分
			BigDecimal bigAreaDirect=new BigDecimal(0);
			//大区间接管理津贴由本大区总监直属分行承担部分
			BigDecimal bigAreAIndirect=new BigDecimal(0);
			//分行以上，底薪和职务津贴之和超出3300的部分由它旗下分行均摊
			BigDecimal fixedMoney=new BigDecimal(0);
			//被推荐人所处分行支出推荐奖励
			BigDecimal recOut=new BigDecimal(0);
			//这个是分行的部门编号
			String deptNo = dictDepartmentEntityXtd.getDeptNo();
			List<DictEmployeeEntityXtd> allEmployee = getAllEmployee(month,deptNo, dictEmployeeServiceXtd, dictDepartmentServiceXtd,dataContractXtdServiceXtd);

			//这里加上分行本人
			if(allEmployee.size()!=0) {
				allEmployee.add(leader);
			}

			if(leader==null) {
				return;
			}
			for (DictEmployeeEntityXtd dictEmployeeEntityXtd : allEmployee) {
				/*if(dictEmployeeEntityXtd==null) {
					System.out.println("dsadassada");
				}*/
				String id = dictEmployeeEntityXtd.getId();
				Map<String, Object> map=new HashMap<>();
				map.put("employeeId", id);
				map.put("payrollMonth", month);
				DataPayrollEntityXtd queryByEmployeeIdAndMonth = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(map);
				BigDecimal firstmonthwage =new BigDecimal(0);
				BigDecimal monthwage =new BigDecimal(0);
				BigDecimal portfee =new BigDecimal(0);
				BigDecimal businesspromotion =new BigDecimal(0);
				BigDecimal newtalent =new BigDecimal(0);
				BigDecimal directordirect =new BigDecimal(0);
				BigDecimal directorindirect =new BigDecimal(0);
				BigDecimal mobilefee =new BigDecimal(0);
				BigDecimal joballowance =new BigDecimal(0);
				BigDecimal branchdirect =new BigDecimal(0);
				BigDecimal socialinsurance =new BigDecimal(0);
				BigDecimal housingfund =new BigDecimal(0);
				BigDecimal reward = new BigDecimal(0);
				BigDecimal separateMoney =new BigDecimal(0);
				if(queryByEmployeeIdAndMonth.getFirstmonthwage()!=null) {
					firstmonthwage = queryByEmployeeIdAndMonth.getFirstmonthwage();
				}
				if(queryByEmployeeIdAndMonth.getMonthwage()!=null) {
					monthwage = queryByEmployeeIdAndMonth.getMonthwage();
				}
				if( queryByEmployeeIdAndMonth.getPortfee()!=null) {
					portfee = queryByEmployeeIdAndMonth.getPortfee();
				}
				if(queryByEmployeeIdAndMonth.getBusinesspromotion()!=null) {
					businesspromotion = queryByEmployeeIdAndMonth.getBusinesspromotion();
				}
				if(queryByEmployeeIdAndMonth.getNewtalent()!=null) {
					newtalent = queryByEmployeeIdAndMonth.getNewtalent();			
				}
				if(queryByEmployeeIdAndMonth.getDirectordirect()!=null) {
					directordirect = queryByEmployeeIdAndMonth.getDirectordirect();
				}
				if(queryByEmployeeIdAndMonth.getDirectorindirect()!=null) {
					directorindirect = queryByEmployeeIdAndMonth.getDirectorindirect();
				}
				if(queryByEmployeeIdAndMonth.getMobilefee()!=null) {
					mobilefee = queryByEmployeeIdAndMonth.getMobilefee();
				}
				if(queryByEmployeeIdAndMonth.getJoballowance()!=null) {
					joballowance = queryByEmployeeIdAndMonth.getJoballowance();
				}
				if(queryByEmployeeIdAndMonth.getBranchdirect()!=null) {
					branchdirect = queryByEmployeeIdAndMonth.getBranchdirect();
				}
				if(queryByEmployeeIdAndMonth.getSocialinsurance()!=null) {
					socialinsurance = queryByEmployeeIdAndMonth.getSocialinsurance();
				}
				if(queryByEmployeeIdAndMonth.getHousingfund()!=null) {
					housingfund = queryByEmployeeIdAndMonth.getHousingfund();
				}
				if(queryByEmployeeIdAndMonth.getReward()!=null) {
					reward = queryByEmployeeIdAndMonth.getReward();
				}			 
				if(queryByEmployeeIdAndMonth.getSeparateMoney()!=null) {
					separateMoney = queryByEmployeeIdAndMonth.getSeparateMoney();
				}			 
				branchDirect=branchdirect;
				employeePay=employeePay.add(firstmonthwage).add(monthwage).add(portfee).add(businesspromotion).add(newtalent).add(directordirect).add(directorindirect).add(separateMoney).add(mobilefee).add(joballowance).add(branchdirect).add(socialinsurance).add(housingfund).add(reward);
				Map<String, Object> mapk=new HashMap<>();
				mapk.put("employeeId", id);
				mapk.put("calTime", month);

				List<DataRecommendEntityXtd> queryByTimeId = dataRecommendServiceXtd.queryByTimeId(mapk);
				if(queryByTimeId!=null) {
					for (DataRecommendEntityXtd dataRecommendEntityXtd : queryByTimeId) {
						recOut=recOut.add(dataRecommendEntityXtd.getMoney());
					}
				}
			}
			//
			Map<String, Object> map=new HashMap<>();
			map.put("employeeId", leader.getId());
			map.put("payrollMonth", month);
			DataPayrollEntityXtd leaderPay = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(map);
			BigDecimal branchdirect2 = leaderPay.getBranchdirect();
			String value = sysConfigService.getValue("groupAchievement.fhjjyc", null);
			//给其他人的分行间接管理津贴，具体给谁了看明细
			branchIndirect= branchdirect2.multiply(new BigDecimal(value));

			String jobNo = leader.getJobNo();
			if("11.0".equals(jobNo)) {
				jobNo="11";
			}
			if("12.0".equals(jobNo)) {
				jobNo="12";
			}
			if("13.0".equals(jobNo)) {
				jobNo="13";
			}
			if("14.0".equals(jobNo)) {
				jobNo="14";
			}
			if("15.0".equals(jobNo)) {
				jobNo="15";
			}
			if("16.0".equals(jobNo)) {
				jobNo="16";
			}
			if("17.0".equals(jobNo)) {
				jobNo="17";
			}
			if("18.0".equals(jobNo)) {
				jobNo="18";
			}
			if(Integer.parseInt(jobNo)>=11&&Integer.parseInt(jobNo)!=71&&Integer.parseInt(jobNo)!=72) {
				//如果是分行以上，要支付区域间接管理津贴，算到他的直辖分行
				BigDecimal areadirect2 = leaderPay.getAreadirect();
				String areavalue = sysConfigService.getValue("areaAchievement.qyjjyc", null);
				//支付的区域间接管理津贴
				areaIndirect = areadirect2.multiply(new BigDecimal(areavalue));
			}

			if(Integer.parseInt(jobNo)>=15&&Integer.parseInt(jobNo)!=71&&Integer.parseInt(jobNo)!=72) {
				//如果是分行以上，要支付大区间接管理津贴，算到他的直辖分行
				BigDecimal bigareadirect2 = leaderPay.getBigareadirect();
				String bigareavalue = sysConfigService.getValue("groupAchievement.dqjjyc", null);
				//支付的大区间接管理津贴
				bigAreAIndirect = bigareadirect2.multiply(new BigDecimal(bigareavalue));
			}
			//查看该分行的上级区域
			String parentNo = dictDepartmentEntityXtd.getParentId();
			//上级区域实体
			DictDepartmentEntity area = dictDepartmentServiceXtd.queryObjectByDeptNo(parentNo);
			if(area!=null) {
				String workNo = dictDepartmentEntityXtd.getEmployeeID();
				//查询monthdir表里的记录
				Map<String, Object> mapp=new HashMap<>();
				mapp.put("areaNo", parentNo);
				mapp.put("calMonth", month);
				List<DataMonthdirectEntityXtd> calmonthinfo = dataMonthdirectServiceXtd.getCalmonthinfo(mapp);
				for (DataMonthdirectEntityXtd dataMonthdirect : calmonthinfo) {
					String basicmonth = dataMonthdirect.getBasicmonth();
					BigDecimal directmoney = dataMonthdirect.getDirectmoney();
					//获得上级某月总业绩
					Map<String, Object> mapp2=new HashMap<>();
					mapp2.put("areaNo", area.getEmployeeID());
					mapp2.put("month", basicmonth);
					//区域回溯某月业绩
					BigDecimal parentAchi = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
					//此分行回溯某月业绩
					Map<String, Object> mapp3=new HashMap<>();
					mapp3.put("branchNo",workNo);
					mapp3.put("month", basicmonth);
					//区域回溯某月业绩
					BigDecimal deptAchi = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp3);
					if(parentAchi!=null) {
						if(deptAchi==null) {
							deptAchi=new BigDecimal(0);
						}
						BigDecimal multiply = new BigDecimal(0);
						if(parentAchi.compareTo(new BigDecimal(0))!=0) {							
							multiply = directmoney.divide(parentAchi,2, BigDecimal.ROUND_HALF_UP).multiply(deptAchi);
						}
						//这边按回溯月累加区域直接管理津贴分摊
						areaDirect=areaDirect.add(multiply);				
					}
				}
			}

			//查看该分行的上级大区
			if(area!=null) {
				DictDepartmentEntity bigArea = dictDepartmentServiceXtd.queryObjectByDeptNo(area.getParentId());
				if(bigArea!=null) {
					String workNo = dictDepartmentEntityXtd.getEmployeeID();
					String deptNo2 = bigArea.getDeptNo();
					//查询monthdir表里的记录
					Map<String, Object> mapp3=new HashMap<>();
					mapp3.put("areaNo", deptNo2);
					mapp3.put("calMonth", month);
					List<DataMonthdirectEntityXtd> calmonthinfo2 = dataMonthdirectServiceXtd.getCalmonthinfo(mapp3);
					for (DataMonthdirectEntityXtd dataMonthdirect : calmonthinfo2) {
						String basicmonth = dataMonthdirect.getBasicmonth();
						BigDecimal directmoney = dataMonthdirect.getDirectmoney();
						//获得上级某月总业绩
						Map<String, Object> mapp2=new HashMap<>();
						mapp2.put("bigAreaNo", bigArea.getEmployeeID());
						mapp2.put("month", basicmonth);
						//区域回溯某月业绩
						BigDecimal parentAchi = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp2);
						//此分行回溯某月业绩
						Map<String, Object> mapp4=new HashMap<>();
						mapp4.put("branchNo", workNo);
						mapp4.put("month", basicmonth);
						//区域回溯某月业绩
						BigDecimal deptAchi = dataContractpayDetailServiceXtd.getGroupAchiByWorkNo(mapp4);
						if(parentAchi!=null) {
							if(deptAchi==null) {
								deptAchi=new BigDecimal(0);
							}
							BigDecimal multiply = directmoney.divide(parentAchi,2, BigDecimal.ROUND_HALF_UP).multiply(deptAchi);
							//这边按回溯月累加大区直接管理津贴分摊
							bigAreaDirect=bigAreaDirect.add(multiply);				
						}
					}

					//上级大区和区域的底薪和职务津贴部分多于3300分摊
					//获取值
					//3300
					String standard1 = sysConfigService.getValue("standard1", null);
					//6600
					String standard2 = sysConfigService.getValue("standard2", null);
					//10500
					String standard3 = sysConfigService.getValue("standard3", null);
					//区域工号
					String araeWorkNo = area.getEmployeeID();
					//大区工号
					String bigAraeWorkNo = bigArea.getEmployeeID();
					//区域负责人
					DictEmployeeEntityXtd areaEmp = dictEmployeeServiceXtd.getListByWorkNo(araeWorkNo);
					//大区负责人
					DictEmployeeEntityXtd bigAreaEmp = dictEmployeeServiceXtd.getListByWorkNo(bigAraeWorkNo);
					//找到分行育成人
					String branchBredNo = leader.getBranchBredNo();
					//这个是育成这个分行的育成人，要分摊3300-6600的部分
					if(branchBredNo!=null&&branchBredNo.length()!=0) {
						DictEmployeeEntityXtd listByWorkNo = dictEmployeeServiceXtd.getListByWorkNo(branchBredNo);
						if(listByWorkNo!=null) {
							Map<String, Object> rollMap=new HashMap<>();
							rollMap.put("employeeId", listByWorkNo.getId());
							rollMap.put("payrollMonth", month);
							DataPayrollEntityXtd queryByEmployeeIdAndMonth = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(rollMap);
							BigDecimal firstmonthwage = queryByEmployeeIdAndMonth.getFirstmonthwage();
							BigDecimal monthwage = queryByEmployeeIdAndMonth.getMonthwage();
							BigDecimal joballowance = queryByEmployeeIdAndMonth.getJoballowance();
							if(firstmonthwage==null) {
								firstmonthwage=new BigDecimal(0);
							} 
							if(monthwage==null) {
								monthwage=new BigDecimal(0);
							} 
							if(joballowance==null) {
								joballowance=new BigDecimal(0);
							}
							//分行育成人底薪加职务津贴
							BigDecimal add = monthwage.add(firstmonthwage).add(joballowance);
							//分摊的部分
							BigDecimal part=new BigDecimal(0);
							//如果不小于6600
							if(!(add.compareTo(new BigDecimal(standard2))==-1)) {
								//6600-3300
								part=new BigDecimal(standard2).subtract(new BigDecimal(standard1));
							}else if(!(add.compareTo(new BigDecimal(standard1))==-1)){
								part=add.subtract(new BigDecimal(standard1));
							}
							//找到育成这个分行的总育成分行数
							Map<String, Object> bredMap=new HashMap<>();
							bredMap.put("branchBredNo", branchBredNo);
							List<DictEmployeeEntityXtd> queryBredNo = dictEmployeeServiceXtd.queryBredNo(bredMap);
							//3300-6600分摊部分				
							BigDecimal branchDiv = part.divide(new BigDecimal(queryBredNo.size()),2, BigDecimal.ROUND_HALF_UP);
							//找区域的育成人，分摊6600-10500部分
							String areaBredNo = areaEmp.getAreaBredNo();
							//这个是育成这个区域的育成人，要分摊6600-10500的部分
							Map<String, Object> rollMap1=new HashMap<>();
							rollMap1.put("employeeId", areaEmp.getId());
							rollMap1.put("payrollMonth", month);
							DataPayrollEntityXtd queryByEmployeeIdAndMonth1 = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(rollMap1);
							BigDecimal monthwage1 = queryByEmployeeIdAndMonth1.getMonthwage();
							BigDecimal joballowance1 = queryByEmployeeIdAndMonth1.getJoballowance();
							if(monthwage1==null) {
								monthwage1=new BigDecimal(0);
							}else if(joballowance1==null) {
								joballowance1=new BigDecimal(0);
							}
							//分行育成人底薪加职务津贴						
							BigDecimal add1 = monthwage1.add(joballowance1);
							//分摊的部分
							BigDecimal part1=new BigDecimal(0);
							//如果不小于6600
							if(!(add1.compareTo(new BigDecimal(standard3))==-1)) {
								//10500-6600,如果超过10500则按10500算，超过10500不在这分摊
								part1=new BigDecimal(standard3).subtract(new BigDecimal(standard2));
								//大于6600低于10500
							}else if(!(add1.compareTo(new BigDecimal(standard2))==-1)) {
								part1=add1.subtract(new BigDecimal(standard2));
							}
							//找到育成这个区域的总育成区域数
							Map<String, Object> bredMap1=new HashMap<>();
							bredMap1.put("areaBredNo", areaBredNo);
							List<DictEmployeeEntityXtd> queryBredNo1 = dictEmployeeServiceXtd.queryBredNo(bredMap1);
							//3300-6600分摊部分,先除以区域个数，再除以本区域分店个数
							FHresult.clear();
							List<DictDepartmentEntityXtd> fhByDeptNo = getFHByDeptNo(area.getDeptNo(), dictDepartmentServiceXtd);
							BigDecimal areaDiv = part1.divide(new BigDecimal(queryBredNo1.size()),2, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(fhByDeptNo.size()),2, BigDecimal.ROUND_HALF_UP);

							//找大区的育成人，分摊10500以上部分
							String bigAreaBredNo = bigAreaEmp.getBigAreaBredNo();
							//这个是育成这个大区的育成人，要分摊10500以上的部分
							Map<String, Object> rollMap2=new HashMap<>();
							rollMap2.put("employeeId", bigAreaEmp.getId());
							rollMap2.put("payrollMonth", month);
							DataPayrollEntityXtd queryByEmployeeIdAndMonth2 = dataPayrollServiceXtd.queryByEmployeeIdAndMonth(rollMap2);
							BigDecimal monthwage2 = queryByEmployeeIdAndMonth2.getMonthwage();
							BigDecimal joballowance2 = queryByEmployeeIdAndMonth2.getJoballowance();
							if(monthwage2==null) {
								monthwage2=new BigDecimal(0);
							}else if(joballowance2==null) {
								joballowance2=new BigDecimal(0);
							}
							//分行育成人底薪加职务津贴						
							BigDecimal add2 = monthwage2.add(joballowance2);
							//分摊的部分
							BigDecimal part2=new BigDecimal(0);
							if(!(add2.compareTo(new BigDecimal(standard3))==-1)) {
								//超过10500的部分
								part2=add2.subtract(new BigDecimal(standard3));									//大于6600低于10500
							}
							//找到育成这个区域的总育成区域数
							Map<String, Object> bredMap2=new HashMap<>();
							bredMap2.put("bigAreaBredNo", bigAreaBredNo);
							List<DictEmployeeEntityXtd> queryBredNo2 = dictEmployeeServiceXtd.queryBredNo(bredMap2);
							//3300-6600分摊部分,先除以区域个数，再除以本区域分店个数
							BigDecimal bigAreaDiv = part2.divide(new BigDecimal(queryBredNo2.size()), 2, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(queryBredNo1.size()),2, BigDecimal.ROUND_HALF_UP).divide(new BigDecimal(fhByDeptNo.size()),2, BigDecimal.ROUND_HALF_UP);
							fixedMoney=fixedMoney.add(branchDiv).add(areaDiv).add(bigAreaDiv);
						}

					}
				}
			}
			teamPay.setAreadirect(areaDirect);
			teamPay.setAreaindirect(areaIndirect);
			teamPay.setBigareadirect(bigAreaDirect);
			teamPay.setBigareaindirect(bigAreAIndirect);
			teamPay.setBranchdirect(branchDirect);
			teamPay.setBranchindirect(branchIndirect);
			teamPay.setCaltime(month);
			teamPay.setDepno(deptNo);
			teamPay.setEmployeeid(leader.getId());
			teamPay.setEmployeepay(employeePay);
			teamPay.setFixedmoney(fixedMoney);
			teamPay.setRecommendout(recOut);
			//这个id是工号
			teamPay.setWorkno(employeeID);
			dataTeampayServiceImplXtd.save(teamPay);
		}
	}
	/**
	 * 输入时间和员工id,判断该员工是否开单（前提本月有实收）
	 */
	public static double judgeAct(String month,String employeeId,DataContractXtdServiceXtd dataContractXtdServiceXtd) {
		double count=0;
		Map<String,Object> map=new HashMap<>();
		map.put("employeeID", employeeId);
		map.put("month", month);
		BigDecimal queryAssessmentCount = dataContractXtdServiceXtd.queryAssessmentCount(map);
		if(queryAssessmentCount!=null) {
			count = queryAssessmentCount.doubleValue();
		}

		if(count>=1) {
			return 1;
		}else{
			return count;
		}

	}
	/**
	 * 输入时间和员工id,看当月离职人员是否算人力
	 */
	public static boolean judgeOutEmp(String contractMonth,String employeeId,HisEmployeeServiceXtd hisEmployeeServiceXtd,DictEmployeeServiceXtd dictEmployeeServiceXtd) {
		Date outorgtime=null;
		DictEmployeeEntity employeeEntity = dictEmployeeServiceXtd.queryObject(employeeId);
		if(employeeEntity!=null) {
			outorgtime = employeeEntity.getOutorgtime();
		}else {
			List<HisEmployeeEntityXtd> hisList = hisEmployeeServiceXtd.queryEmployeeByHisId(employeeId);
			if(hisList!=null&&hisList.size()!=0) {
				outorgtime = hisList.get(0).getOutorgtime();
			}
		}
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMM");
		String outTime=null;
		if(outorgtime!=null) {
			outTime = sdf.format(outorgtime);
			if(outTime.equals(contractMonth)) {
				return true;
			}else {
				//离职时间大于开单年月也算人力
				if(Integer.parseInt(outTime)>=Integer.parseInt(contractMonth)) {
					return true;
				}else {
					return false;
				}

			}
		}else {
			return true;
		}

	}
	/**
	 * 输入时间和员工id,判断该员工是否开单（本月有应收即可）
	 */
	public static double judgeActShould(String month,String employeeId,DataContractXtdServiceXtd dataContractXtdServiceXtd) {
		double count=0;
		Map<String,Object> map=new HashMap<>();
		map.put("employeeID", employeeId);
		map.put("month", month);
		BigDecimal queryAssessmentCount = dataContractXtdServiceXtd.queryAssessmentCount(map);
		if(queryAssessmentCount!=null) {
			count = queryAssessmentCount.doubleValue();
		}

		if(count>=1) {
			return 1;
		}else{
			return count;
		}

	}

}